嗨,我试图上传一个图像使用PHP脚本。和什么很奇怪的是我只在Internet Explorer中收到以下错误地方有什么脚本正常工作:PHP中的文件上传问题
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']修复它。 (对不起,我没有提到$大变量是在我之前没有发布的脚本中定义的) – Ross 2009-10-23 18:19:33