【发布时间】:2025-12-04 13:00:02
【问题描述】:
您好,我正在尝试使用 php 脚本上传图片。真正奇怪的是,我只在 Internet Explorer 中收到以下错误,其他任何地方的脚本都可以正常工作:
Warning: move_uploaded_file(pictures/) [function.move-uploaded-file]: failed to open stream: Is a directory in /home/tntauto1/public_html/admin_add1.php on line 59
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpcJnHZE' to 'pictures/' in /home/tntauto1/public_html/admin_add1.php on line 59
Warning: copy() [function.copy]: The first argument to copy() function cannot be a directory in /home/tntauto1/public_html/admin_add1.php on line 60
这是脚本:
if(is_uploaded_file($_FILES['image']['tmp_name'])){
if($_FILES['image']['type'] == 'image/jpeg'){
$original = 'original_'.$v_id.'.jpg';
$large = 'large_'.$v_id.'.jpg';
$small = 'small_'.$v_id.'.jpg';
}elseif($_FILES['image']['type'] == 'image/gif'){
$original = 'original_'.$v_id.'.gif';
$large = 'large_'.$v_id.'.gif';
$small = 'small_'.$v_id.'.gif';
}else{
$error = 'Error: The image could not be uploaded. It must be in .jpg, .jpeg or .gif format.';
}
if(move_uploaded_file($_FILES['image']['tmp_name'],'pictures/'.$large)){}
copy('pictures/'.$large,'pictures/'.$small);
$imgsize = getimagesize('pictures/'.$large); //>>>>>>>>>>>>>>>>>>>>>>>>>>>>---- Resize to 480 X 360
$width = $imgsize[0];
$height = $imgsize[1];
if(($width > 480) || ($height > 360)){//resize the image
$ratio = $width / $height;
if(100 / $ratio >= 80){//calculates if height of uploaded image is too large
$new_width = floor(360 * $ratio);
$new_height = 360;
}elseif(150 * $ratio > 100){// calculate if width of uploaded image is too large
$new_width = 480;
$new_height = floor(480 / $ratio);
}
if($_FILES['image']['type'] == 'image/jpeg'){
$img = imagecreatefromjpeg('pictures/'.$large);
$img_copy = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($img_copy,$img,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($img_copy,'pictures/'.$large,100);
}
if($_FILES['image']['type'] == 'image/gif'){
$img = imagecreatefromjpeg('pictures/'.$large);
$img_copy = imagecreatetruecolor($new_width,$new_height);
imagecopyresampled($img_copy,$img,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($img_copy,'pictures/'.$large,100);
}
}
【问题讨论】:
-
大家好,谢谢大家的意见。不按文件类型检查它 $_FILES['name']['type'] 修复了它。 (对不起,我没有提到 $large 变量是在我没有发布的脚本中定义的)
标签: php file-upload