PHP - upload.class image and $_FILES
I'm using class.upload.php to upload pictures onto the server. Here is my form:
<form action="<?="http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];?>" method="post" enctype="multipart/form-data">
<table style="width: 100%; padding-top: 20px;">
<tr>
<td>Image file:</td>
<td><input type="file" name="image_file" /></td>
</tr>
<tr>
<td> </td>
<td align="right"><input type="submit" name="add_new" value="Add image" /><td></td>
</tr>
</table>
</form>
In php code I do:
if( array_key_exists('add_new', $_POST) )
{
echo 'add new is in array';
echo '<pre>';
print_r($_POST);
print_r($_FILES);
echo '</pre>';
$handle = new Upload($_FILES['image_file']);
...
}
Here is an output of print_r:
Array
(
[image_file] => somefile.png
[add_new] => Add image
)
Array
(
)
As you can see second array is empty ($_FILES), so image doesn't upload. Why?
-
开发者_Python百科
- operating system : Linux
- PHP version : 5.2.12
- GD version : 2.0.34
- supported image types : png jpg gif bmp
- open_basedir : /home/httpd/vhosts/%site%/httpdocs:/tmp
Have you tried with images smaller than the post_max_size ini setting? Also, make sure your /tmp has space and is writable.
Other resources:
1) Long list of causes here: http://getluky.net/2004/10/04/apachephp-_files-array-mysteriously-empty/
2) From http://php.net/manual/en/features.file-upload.php
As said before if POST size exceeds server limit then $_POST and $_FILES arrays become empty. You can track this using $_SERVER['CONTENT_LENGTH'].
For example:
<?php
$POST_MAX_SIZE = ini_get('post_max_size');
$mul = substr($POST_MAX_SIZE, -1);
$mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)));
if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) $error = true;
?>
精彩评论