Problem with file upload..

Discussion in 'PHP' started by adamjblakey, May 9, 2007.

  1. #1
    Hi,

    I am having problems with a file upload. Basically i am trying to upload a file using php. My problem lies when i try and upload a file bigger than 500kb the script times out as soon as the form is submitted. I have check the upload limit on the server and this is set to 2meg so there should not be a problem there.

    
    	move_uploaded_file($_FILES['file']['tmp_name'], './files/'.$_FILES["file"]["name"]);
    
    		$db = file('./data.db');
    		$lastid = 0;
    		foreach ($db AS $d) {
    			list($id, $user) = explode('|', $d);
    			$lastid = $id;
    		}
    		$db = implode("",file('./data.db'));
    
    		$fh = fopen('./data.db', "w");
    		
    		$username = $_POST["username"];
    		$title = $_POST["title"];
    		$description = $_POST["description"];
    		$filename = $_FILES["file"]["name"];
    		
    		fwrite($fh, $db.($lastid+1)."|".$username."|".$title."|".$description."|".$filename."|\n");
    		fclose($fh);
    
    Code (markup):
    Any ideas anyone?

    Cheers,
    Adam
     
    adamjblakey, May 9, 2007 IP
  2. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Check the following values from your php.ini: upload_max_filesize, post_max_size, max_input_time.

    Additional info here:
    http://www.php.net/features.file-upload
     
    lemaitre, May 9, 2007 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
  4. lemaitre

    lemaitre Peon

    Messages:
    61
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #4
    max_input_time = 60 is a little low for a post_max_size of 8M.

    I don't know if that's the problem though. I'm not sure what you mean when you say the script times out as soon as the form is submitted. If it is timing out because of the max_input_time setting, that would take 60 seconds.
     
    lemaitre, May 9, 2007 IP
  5. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #5
    The script won't be executed until the file is sent to the server. And the moving shouldn't take a second once it's uploaded. So there must be another reason for the time out. Can you post your code so I can try it?
     
    nico_swd, May 9, 2007 IP
  6. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #6
    This is the form that submits to the php page:

    
    
    <form method="post" action="file.php?add=file" enctype="multipart/form-data">
    
    <p class="style1"><b>Username: </b><select name="username">
    <?php
    
    $unames = file("files/usernames.php");
    foreach($unames AS $line) {
    	list($user, $spare1, $spare2) = explode('|', $line); 
    	print "<option>$user";
    }
    
    ?>
    </select> <b>File: </b><input type="file" name="file"><br /><b>Title: </b><input type="text" name="title">
    <br>
    <strong>Description:</strong><br />
    
    <textarea style="width: 100%;" rows="4" name="description">Description of this file</textarea>
    
    <input type="submit" value="Add File"></p></form>
    Code (markup):
    Then this is the php form:

    
    
    	move_uploaded_file($_FILES['file']['tmp_name'], './files/'.$_FILES["file"]["name"]);
    
    		$db = file('./data.db');
    		$lastid = 0;
    		foreach ($db AS $d) {
    			list($id, $user) = explode('|', $d);
    			$lastid = $id;
    		}
    		$db = implode("",file('./data.db'));
    
    		$fh = fopen('./data.db', "w");
    		
    		$username = $_POST["username"];
    		$title = $_POST["title"];
    		$description = $_POST["description"];
    		$filename = $_FILES["file"]["name"];
    		
    		fwrite($fh, $db.($lastid+1)."|".$username."|".$title."|".$description."|".$filename."|\n");
    		fclose($fh);
    
    
    Code (markup):
    Any ideas?
     
    adamjblakey, May 10, 2007 IP