我有一個要求在服務器上以2大小,正常和小尺寸上傳圖像。PHP腳本無法上傳服務器上的圖像
所以我發送HTTP請求到PHP文件,我是能夠成功地以正常形式上傳圖片服務器上,
但是,當我試圖調整大小,然後上傳在服務器上,它沒有上傳。 。
因此,這裏是我的PHP腳本
<php
define ("MAX_SIZE","400");
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$image =$_FILES['userfile']['name'];
$uploadedfile = $_FILES['userfile']['tmp_name'];
if ($image)
{
$filename = stripslashes($_FILES['userfile']['name']);
$extension = getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
$errors=1;
}
else
{
$size=filesize($_FILES['userfile']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
$errors=1;
}
if($extension=="jpg" || $extension=="jpeg")
{
$uploadedfile = $_FILES['userfile']['tmp_name'];
$src = imagecreatefromjpeg($uploadedfile);
}
list($width,$height)=getimagesize($uploadedfile);
$newwidth = 70;
$newheight = 70;
$tmp = imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);
$file_name = substr (md5(uniqid(rand(),1)), 5, 15);
$iconuploaddir = "/home/announce/public_html/TravelApp/images/$output/icons/";
$file = basename($_FILES['userfile']['name']);
$newname = $file_name . $file;
$uploadIconfile = $iconuploaddir . $newname;
if (move_uploaded_file($temp, $uploadIconfile)) {
$imagepath = $baseuploaddir;// Give the path where the image saves. or print some messages
}
imagedestroy($src);
imagedestroy($tmp);
}
}
}
?>
我猜move_uploaded_file($溫度,$ uploadIconfile))是問題的主要原因
請幫助我。
爲什麼有人會喜歡閱讀大量部分評論的代碼? – k102 2012-01-18 11:33:55
@ K102,因爲他正在求救 – 2012-01-18 11:40:21