nav33n 472 Purple hazed! Team Colleague Featured Poster

Everything about php here and also here .

nav33n 472 Purple hazed! Team Colleague Featured Poster

No! I don't have such a large file!

Okay! Since I was jobless, I created a file of 40+ mb (and around 8 lac dummy records) and tried to upload it.. (ofcourse, I had to increase upload_max_filesize = 100M and post_max_size = 100M ) to 100mb.

Its working fine.. :) The script is still running,

Showing rows 0 - 29 (~12,8351 total, Query took 0.0006 sec)

and its still inserting the records..

Edit 2:

Showing rows 0 - 29 (~74,7061 total, Query took 0.0007 sec)

and still inserting..
No problem with your script. Now, I am confused. :S

nav33n 472 Purple hazed! Team Colleague Featured Poster

I tested your code with a small csv file and it works. :-/

The only thing (*I think*) that can go wrong is datatype of the columns not matching with the provided values.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Huh! It created rows but didn't insert data ? :S How is that possible ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

This can be done using ajax.
I am not really good at Ajax, but, I think, this is what you are trying to achieve. I modified the script from http://w3schools.com/php/php_ajax_suggest.asp to meet your requirement!
This is index.php

<html>
<head>
<script src="clienthint.js"></script> 
</head>
<body>
<form name="form1"> 
<input type="button" name="button" value="button" onclick="callAjax(1);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(2);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(3);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(4);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(5);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(6);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(7);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(8);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(9);" /><br />
<input type="button" name="button" value="button" onclick="callAjax(10);" /><br />
</form>
<p><span id="txtHint"></span></p> 
</body>
</html>
//callAjax is an ajax function. You pass the id of the image as parameter.

This is clienthint.js

var xmlHttp

function callAjax(id) {
	
	if (id.length==0) { 
  	document.getElementById("txtHint").innerHTML=""
  	return
  } 
	xmlHttp=GetXmlHttpObject()
	if (xmlHttp==null) {
  	alert ("Browser does not support HTTP Request")
  	return
  } 
	var url="gethint.php"
	url=url+"?id="+id
	
	xmlHttp.onreadystatechange=stateChanged 
	xmlHttp.open("GET",url,true)
	xmlHttp.send(null)
}


function stateChanged(){ 
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
 	{ 
 		document.getElementById("txtHint").innerHTML=xmlHttp.responseText 
 	} 
}

function GetXmlHttpObject() {
	var xmlHttp=null;
	try {
 		// Firefox, Opera 8.0+, Safari
 		xmlHttp=new XMLHttpRequest();
 	}
	catch (e) {
 		// Internet Explorer
 			try {
  			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  		}
 			catch (e) {
  			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
 	}
	return xmlHttp;
}

This is gethint.php where you execute your sql query.

<?php
if(isset($_REQUEST['id'])) {
	$id = $_REQUEST['id']; 
	echo $query = "update table set xyz='blah' where id='$id'";
	echo "<br />";
}
?>

Cheers,

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$time = "37:00";
list($hrs, $mins) = explode(":", $time);
$mins += $hrs * 60;
$endresult = $mins/5;
echo date("H:i",mktime(0,$endresult,0,0,0,0));
?>

Now ?

R0bb0b commented: Thankyou +1
kvdd commented: He gives me a complete solution, thanks nav33n! +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't know about C program, but, I wrote a simple java program and it worked. This is how I did.

<?php
if(isset($_POST['submit'])) {
	$filename = $_POST['filename']; //user will enter the filename with .java extension
	$program=stripslashes($_POST['program']); // java program
	$fp = fopen($filename,"w+"); //open the file and write the program to that file
	fwrite($fp,$program);
	fclose($fp);
	$path="c:\\j2sdk1.4.2_13\\bin"; // where the program exist. 
	copy($filename,$path."/".$filename); //copy to the bin directory of java for execution
	unlink($filename); //delete the file from www folder
	chdir($path); //change to directory where java is located
	exec("javac ".$filename); //compile java program
	$actualname = substr($filename, 0, strpos($filename,".")); //get the filename to execute it
	$contents = exec("java ".$actualname);  //execute java program
	echo $contents; //print the contents
}
?>
<html>
<body>
<form method="post" action="executejava.php">
Filename: <input type="text" name="filename" /><br />
<textarea name="program" cols="40" rows="30"></textarea><br />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>

Hope that helps!
Cheers,
Naveen

nav33n 472 Purple hazed! Team Colleague Featured Poster

I guess, if its not very difficult to allow editing some posts forever, while keeping the 30 mins rule with all other posts, it should be done.

I think, that needs a lot of work and also not a good idea !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Umm.. Just curious, how are you joining those 2 tables ? On what condition ?
If there is no condition for join, wouldn't it give the cartesian product of 2 tables ?
That is, first, it will select all the records from artists_details where ethnicity is 'maori'. Then, it will select the records from attendance table where visit_date >= June 1st and visit_date <= June 19th. :-/

nav33n 472 Purple hazed! Team Colleague Featured Poster
<html>
<head>
</head>
<body>
<script type="text/javascript" src="wz_tooltip.js"></script>
<script type="text/javascript" src="tip_centerwindow.js"></script>
<script type="text/javascript" src="tip_followscroll.js"></script>
<form method="post">
<select name="test">
<option value="1" onmouseover="Tip('Option 1');" onmouseout="UnTip();">1</option>
<option value="2" onmouseover="Tip('Option 2');" onmouseout="UnTip();">2</option>
<option value="3" onmouseover="Tip('Option 3');" onmouseout="UnTip();">3</option>
<option value="4" onmouseover="Tip('Option 4');" onmouseout="UnTip();">4</option>
<option value="5" onmouseover="Tip('Option 5');" onmouseout="UnTip();">5</option>
</select>
</form>
</body>
</html>

Works fine for <option> tag.

blufab commented: Rapid responder, with good input +2
nav33n 472 Purple hazed! Team Colleague Featured Poster
nav33n 472 Purple hazed! Team Colleague Featured Poster

But is there a way to avoid the confirm dialog box in IE while using window.close ?
And, window.close doesn't work in FF :-/

nav33n 472 Purple hazed! Team Colleague Featured Poster

Great! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

You are welcome.. I *hope* by the time you return, you will see it uploaded! :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yeah.. it does.. Try opening a 30 mb file in notepad.. You can take a nap by the time it opens the file.. Umm.. I don't know how to process a large file.. Lets see if someone else has an idea :(

nav33n 472 Purple hazed! Team Colleague Featured Poster

:?: hmmm.. keep printing $data.. Ie., print_r($data); and see if it prints any data for the large file.. also check how many records does it print..

nav33n 472 Purple hazed! Team Colleague Featured Poster

No matter what you have for max_execution_time in php.ini, But if set_time_limit is 0 (in your script), it uses set_time_limit(0) because its executed during the runtime!

nav33n 472 Purple hazed! Team Colleague Featured Poster

I think

foreach ($result as $entry) {

$result is null or doesn't return an array.

nav33n 472 Purple hazed! Team Colleague Featured Poster

max_execution_time = 60 means the script can take a maximum of 60 seconds to execute (and since you are trying to upload a file which is around 30mb, it will take more than umm..(10 mins ?) long time to process!) . So, you can either set it to 0 or use set_time_limit(0) in your script. If you are working on file uploads, then you have to remove the semicolon before upload_tmp_dir.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Nav33n would be the one to listen to in this thread

Lol.. no.. I got to know few things after reading your posts ! I wasn't aware of the 'in depth bits and bytes calculation' ! ;) electronics! eh ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

In php, we make use of microtime to find the execution time.

$starttime = microtime();
$query = mysql_query("select * from table");
$endtime = microtime();

Then calculate the difference between $starttime and $endtime. I am sure you can do the same in java as well !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Put set_time_limit(0); on top of your script.
http://in.php.net/set_time_limit

maydhyam commented: Great Job.....Thanks :) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

:$ I am sorry !!! fgetcsv itself returns an array. You can directly use $data[0],$data[1] and so on..

nav33n 472 Purple hazed! Team Colleague Featured Poster

max_execution_time is used if you have a script which takes more than 30 seconds to execute. When you set max_execution_time as 0, the execution time of the script is removed. That's what I use when I have a process a large csv file. :-/ But I don't think it will work in this case.

nav33n 472 Purple hazed! Team Colleague Featured Poster

I checked the demo here, http://www.protware.com/e_demo.htm and the only thing I found was right click was disabled. When I saved the page, It downloaded the images "new","next" and "prev". :-/ looks like fake to me! (not sure though)

nav33n 472 Purple hazed! Team Colleague Featured Poster

What exactly do you want ? How is the value stored in the database and how do you want to split it ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Can you do a thing ? Can you print $data and tell us what it prints ? ( And also, print_r($data_array); )
Btw, You can ignore notices by using error_reporting(E_ALL ^ E_NOTICE);

nav33n 472 Purple hazed! Team Colleague Featured Poster

Since the delimiter you are using is ,, you should explode the data on , and not ;. And also, You don't need move_uploaded_file in your script.

nav33n 472 Purple hazed! Team Colleague Featured Poster

AFAIK, you cant. When a page is loaded, the images are downloaded into the temporary internet files folder. Even if you disable right click, the user can save the webpage and all the images can be saved in the user's computer !

nav33n 472 Purple hazed! Team Colleague Featured Poster

lol..You can increase the execution time limit, by either changing max_execution_time to 0 (in php.ini ) or use set_time_limit(0); in your script.

Ignore this post !

for($i=0;$i<999999999999;$i++) {
for($i=0;$i<999999999999;$i++) {
$alpha[] = --$i . " " . $i . " " . ++$i;
}
}

This will crash your browser anyway ;)

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$subject = "PHP Hypertext Preprocessor";
$pattern = '/xt/';
preg_match($pattern, $subject, $matches, PREG_OFFSET_CAPTURE);
print "<pre>";
print_r($matches);
print "</pre>";
?>

$matches[1] returns 11.
http://in2.php.net/manual/en/function.preg-match.php
It works but I didn't understand the concept of flags !

nav33n 472 Purple hazed! Team Colleague Featured Poster

Try changing

memory_limit = 8M ; Maximum amount of memory a script may consume (8MB)

in php.ini .
Btw, I am not really sure if this will work !

nav33n 472 Purple hazed! Team Colleague Featured Poster

I don't know what you mean by saving a php file. If you have installed apache, you can type http://localhost/php-file-name to execute your script.

Btw, If you are new to php, I would suggest you to install wamp . Wamp is a bundled package of php, mysql and apache. Just install it and start working !

Nick Evan commented: Good tip on Wamp! +6
nav33n 472 Purple hazed! Team Colleague Featured Poster

When the user logs in, add his username to the session and append the username to the upload directory and list the files.

nav33n 472 Purple hazed! Team Colleague Featured Poster

Software ? you mean the editor ? There are so many. Zend studio is good, but expensive. If you want a free editor, you can use phpeclipse, devphp, notepad++ and so on.

nav33n 472 Purple hazed! Team Colleague Featured Poster

It doesn't matter if there is only 1 statement in the condition. But, its a good practice to use braces :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

For "quick learning" you can start here . For php reference guide and detailed php functions description, you can check php.net ( http://www.php.net/manual/en/ )

sreein1986 commented: Thanx very much 4 ur quick reply +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

What is the error ?

nav33n 472 Purple hazed! Team Colleague Featured Poster
<html>
<body>
<form method="post" name="test">
Name : <input type="text" name="name" /><br />
<input type="submit" name="submit" value="submit" />
<input type="button" name="button" value="Reset" onclick="javascript: document.test.reset();" />
</form>
</body>
</html>

Reset works fine this way!

nav33n 472 Purple hazed! Team Colleague Featured Poster
<?php
$a = 1;
$b = 2;
$c = 3;
$alpha = $a." ".$b." ".$c;
echo $alpha;
//prints 1 2 3
echo "<br />";
list($a1,$b1,$c1) = explode (" ",$alpha);
echo $a1; //prints 1
echo $b1; //prints 2
echo $c1; //prints 3
?>

. is the concatenation operator not + !

OmniX commented: Spot on as usual ;) +1
nav33n 472 Purple hazed! Team Colleague Featured Poster

As in this example,

val1_1;val1_2;val1_3;val1_4
val2_1;val2_2;;val2_4

Notice that there is no val2_3. But there is a whitespace in the place of val2_3. So, there are fixed number of columns. I would then explode each row and separate the values.

$data_array = explode(";",$data); 
$value1 = $data_array[0];
$value2 = $data_array[1];
$value3 = $data_array[2];
$value4 = $data_array[3];
//since we know the number of columns in csv file, we can do it this way and even if a column is empty, nothing happens.
$query = "Insert into table (col1,col2,col3,col4) values ('$value1','$value2','$value3','$value4')";
...

This is how I do it.. Maybe someone else has a different idea ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Exactly ! You need to specify the column names in your query..

nav33n 472 Purple hazed! Team Colleague Featured Poster

What if $data has an empty column ? For example, instead of
'test1','test2','test3' if it has 'test1','test3' , then your query will definitely fail (because the column count in the table will not match with the values given).
Did you execute the query in query browser ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

How do you determine which value in $data to be inserted into which column ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

phpmyadmin is an application to manage mysql databases just like mysql query browser :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

There is something wrong with your insert query. You can try it this way. insert into tablename (col1, col2, col3, ..) values ('val1','val2','val3',...) .
Also, you can execute this query in phpmyadmin to see if it executes without any error. :)

nav33n 472 Purple hazed! Team Colleague Featured Poster

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "c:/wamp/tmp"

I don't know whats the system default tmp folder. But I would suggest you to create a temporary folder with all the permissions. Did you print the query ? What does it print ?

nav33n 472 Purple hazed! Team Colleague Featured Poster

Yep. I am trying to upload a file. It doesn't really matter what you do with the uploaded file. You can either upload/store it on the file system or open it and process the data in the file. I believe the problem is with the query and not the file upload.
Btw, check if you have specified a tmp folder path (upload_tmp_dir) in php.ini .

nav33n 472 Purple hazed! Team Colleague Featured Poster

I checked your code, replaced your query with move_uploaded_file. It worked fine. I believe something is going wrong in the insert query. Print out the query, remove @ from mysql_query, use die(mysql_error()); . Everything else seems fine.
Here is the edited code. Try it out. If it uploads the file, then you know where the problem is!

<tr>
    <td colspan="6">
		  	<form action="<? echo $_SERVER['REQUEST_URI']; ?>" enctype="multipart/form-data" method="post">
				<table>					
				  <tr>
					  <td>
					      <p align="left"><span class="style4 style25 style28">Bill Uploader</span></p>
					      <p align="left"><span class="style21 style29">The Bill Uploader works in 2 steps.</span></p>					  </td>
				  </tr>
   				  <tr><td><p>&nbsp;</p></td></tr>
				  <tr>
				  	<td>
				      <table width="950" border="0" align="center" cellpadding="1" cellspacing="0" >
						<tr>
						  <td><p>&nbsp;</p></td>
						  <td colspan="4" bgcolor="#006600">
						  	<p align="left" class="style32">
						  <span class="style21  style33">Step 1: Browse for file</span></p>						  </td>
						  <td><p>&nbsp;</p></td>
						</tr>
						<tr>
						  <td><p>&nbsp;</p></td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td width="125" bgcolor="#006600" scope="row"><div align="left" class="style13 style29 style31">Browse</div></td>
						  <td width="356" bgcolor="#006600">
						  	<div align="left">
								<strong>
									<input type="file" name="file" />
								</strong>							</div>						  </td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td><p>&nbsp;</p></td>
						</tr>
						<tr width="950">
						  <td><p>&nbsp;</p></td>
						  <td colspan="4" bgcolor="#006600">
						  	<p align="left"><strong>
							  <span class="style21 style30">Step 2: Upload the file selected</span></strong></p>						  						  </td>
						  <td><p>&nbsp;</p></td>
						</tr>
						<tr>
						  <td><p>&nbsp;</p></td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td bgcolor="#006600">
						  <div align="left">
						  	<strong>
					      		<input type="submit" value="Upload" name="btnSubmit" />
						  	</strong>						  </div>  						  </td>
						  <td bgcolor="#006600"><p>&nbsp;</p></td>
						  <td><p>&nbsp;</p></td>
						</tr>
					  </table>  				    </td>
				</tr>
			</table>
		</form>	</td>
  </tr>
  <tr>
  	<td colspan="6" >
		
	  <div align="left" class="style29">
		<?
		/*
			include ("./connect.php");
			global $conn;
		*/
			ini_set("display_errors", "1");
			error_reporting (E_ALL);
			
			if(count($_FILES) > 0)
			{
					$ext = "";
				$ext = substr(trim($_FILES["file"]["name"]), -4);
				$allowedext = array(".txt", ".csv", ".sql");
				
				if(in_array($ext, $allowedext))
				{
					$filename = $_FILES['file']['tmp_name'];
					
					/*
					//$fh = fopen($_FILES['file']['tmp_name'], 'r');
					$handle = fopen($filename, "r");
					
					while (($data = fgetcsv($handle, 100000, ',', …
nav33n 472 Purple hazed! Team Colleague Featured Poster

Okay ! I did a quick test. I changed post_max_size to 80M and upload_max_filesize to 80M. I could upload a file of size 40mb (I didn't try 80mb!).

Upload: Toss the feather.divx
Type: video/divx
Size: 41345.8066406 Kb
Temp file: C:\wamp\tmp\php29.tmp
Stored in: upload/Toss the feather.divx

Maybe, You are using something like this ? <input type="hidden" name="MAX_FILE_SIZE" value="100000" />