【发布时间】:2012-01-17 05:31:44
【问题描述】:
尝试上传 .JPG 文件时出现以下错误。
Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in H:\Programs\webserver\root\media\images\upload.php on line 43
以下是upload.php文件的一部分:
if(isset($_FILES['files']))
{
$cat = $_POST['cat'];
$title = $_POST['title'];
$album = $_POST['album'];
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name)
{
// get dimensions of uploaded images
echo $temp = $_FILES['files']['tmp_name'][$key]; //location of file
echo $type = $_FILES['files']['type'][$key]; //image type
echo $size = $_FILES['files']['size'][$key]; // image size
>> line 43 >>**echo $size2 = getimagesize($temp); //function to get info of file and put into array**
echo $width = $size2[0]; // first part of the array is the image width
echo $height = $size2[1]; // second part fo the array is the image width
if($type == 'image/jpeg')
{
$filetype = '.jpeg';
}else{
$filetype = str_replace('image/','',$type);
}
$random_name = rand(1000,9999).rand(1000,9999).rand(1000,9999).rand(1000,9999);
$path = 'img/'.$random_name . $_FILES['files']['name'][$key];
$thumb_path = 'img/thumb_/'.$random_name .$_FILES['files']['name'][$key];
我有另一个 .jpg 图像文件,我一直在上传以测试哪个可以正常上传,.png 和 .gif 文件也可以正常上传。
只是补充一点,我尝试了更多类似大小的图像文件并收到相同的错误。 第一个图像文件是 4.2MB,第二个是 5MB。为什么文件大小会阻止它上传?
当使用 $_FILES['files']['error'][$key]; - 它返回 1。
这是我在使用 print_r 时得到的:
Array ( [files] => Array ( [name] => Array ( [0] => DSCN0354.JPG ) [type] => Array ( [0] => ) [tmp_name] => Array ( [0] => ) [error] => Array ( [0] => 1 ) [size] => Array ( [0] => 0 ) ) )
【问题讨论】:
-
你上传的图片有多大,失败了?
-
您是否考虑过使用
print_r($_FILES)来查看阵列中的实际内容?如果没有,请执行此操作并将输出添加到您的问题中。 -
我猜你没有在这里粘贴完整的代码。
-
Why would the file size stop it uploading?因为php设置限制了它。查找upload_max_filesize 和post_max_size。而且 4.2 MB 与 5 MB 不同
标签: php image-processing