嗨,我試圖上傳一個圖像使用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