Page 1 of 1

PHP upload fails if 500k and times out if 1.5M

Posted: Tue Jul 22, 2008 8:06 pm
by rocksolidhq
Hey folks,

It's just as i've stated. If i select an image of 500k to upload the page fails out immediately and never tries to upload a file (i'm watching the temp folder). If i select an image of 1.5M the page loads for a few minutes and times out. In the background, i see that the file starts to upload but then just stops a few seconds after it starts after reaching 500-700k.

Code: Select all

 
<form enctype="multipart/form-data" id="addForm" name="addForm" method="post" action="salesAdminBus.php">
 
/*snip other data fields collected in the form...*/
 
<input type="hidden" name="MAX_FILE_SIZE" value="10000000000" />      
  <p>
    <label>Add a picture
      <input type="file" name="userfile" />
    </label>
  </p>
  <input type="submit" name="action" value="add" />
 
hopefully that's all the relevent code. Let me know if more would be helpful.

thanks in advance,
dean

Re: PHP upload fails if 500k and times out if 1.5M

Posted: Tue Jul 22, 2008 8:20 pm
by manixrock
do a dump of the $_FILES variable here. Use this to get it:

Code: Select all

echo '<pre>'.print_r($_FILES,1).'</pre>';

Re: PHP upload fails if 500k and times out if 1.5M

Posted: Tue Jul 22, 2008 8:43 pm
by rocksolidhq
for a small file, which does not actually seem to even start getting created in the tmp folder i get:

Array
(
[userfile] => Array
(
[name] => Us.jpg
[type] => image/pjpeg
[tmp_name] => C:\WINDOWS\TEMP\phpF4FE.tmp
[error] => 0
[size] => 223525
)

)

Re: PHP upload fails if 500k and times out if 1.5M

Posted: Tue Jul 22, 2008 8:48 pm
by manixrock
the file in tmp gets deleted if nothing is done with it. Check if the file is actually uploaded in the script where you dump the $_FILES like this:

Code: Select all

is_uploaded_file($_FILES['userfile']['tmp_name'])

Re: PHP upload fails if 500k and times out if 1.5M

Posted: Tue Jul 22, 2008 9:27 pm
by rocksolidhq
Hey,

i put the line you suggested right after the last one, which is at the top of the file, but it returns nothing.
i don't know if it's a red herring but the files larger than about 500k start to upload (i can see them grow to 500-700k almost instantly) and then they just hang until it times out.

thanks a mill,
dean

Re: PHP upload fails if 500k and times out if 1.5M

Posted: Tue Jul 22, 2008 9:34 pm
by manixrock
i put the line you suggested right after the last one, which is at the top of the file, but it returns nothing
use var_dump() to see what it returns. It probably returned false which is printed as an empty string. This may be a cause of MAX_FILE_SIZE. Try removing the hidden input and see if that works.

Re: PHP upload fails if 500k and times out if 1.5M

Posted: Tue Jul 22, 2008 10:05 pm
by rocksolidhq
Hey,

i just found that the print_r command was causing even the smaller files to hang but at least i had time to see that the files were being uploaded and then stalling. this time the files being uploaded were about 250k and the temp files peaked at about 170k.

Anyway, i commented out the print_r command and the result of the var_dump is:

array(1) {
["userfile"]=>
array(5) {
["name"]=>
string(6) "Us.jpg"
["type"]=>
string(11) "image/pjpeg"
["tmp_name"]=>
string(27) "C:\WINDOWS\TEMP\phpF808.tmp"
["error"]=>
int(0)
["size"]=>
int(223525)
}
}


thanks,
dean

Re: PHP upload fails if 500k and times out if 1.5M

Posted: Wed Jul 23, 2008 9:04 am
by manixrock
Try creating a simple test file (asrecomended by the php manual: http://www.php.net/features.file-upload):

Code: Select all

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.
 
$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
 
echo '<pre>';
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";
}
 
echo 'Here is some more debugging info:';
print_r($_FILES);
 
print "</pre>";
 
?>
 
<!-- The data encoding type, enctype, MUST be specified as below -->
<form enctype="multipart/form-data" action="__URL__" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>
If this still gives you problems, then the problem is with your server setup (in php.ini), not with the code.