我正在使用class.upload.php将图片上传到服务器上。这是我的表格:
<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>
在PHP代码中我做:
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']);
...
}
这是print_r的输出:
Array
(
[image_file] => somefile.png
[add_new] => Add image
)
Array
(
)
正如您所看到的,第二个数组为空($ _FILES),因此图像无法上传。为什么呢?
答案 0 :(得分:1)
您是否尝试使用小于post_max_size ini设置的图像?另外,请确保您的/ tmp有空格且可写。
其他资源:
1)这里有很长的原因列表:http://getluky.net/2004/10/04/apachephp-_files-array-mysteriously-empty/
2)来自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;
?>