Php脚本无法在服务器上上载图像
我有一个要求,上传在服务器上的图像在2大小,正常和小尺寸 所以我向php文件发送http请求,我成功地以正常形式将图像上传到服务器上 但当我试图调整大小,然后上传到服务器上,它不是上传 这是我的php脚本Php脚本无法在服务器上上载图像,php,iphone,ios,image,Php,Iphone,Ios,Image,我有一个要求,上传在服务器上的图像在2大小,正常和小尺寸 所以我向php文件发送http请求,我成功地以正常形式将图像上传到服务器上 但当我试图调整大小,然后上传到服务器上,它不是上传 这是我的php脚本 <php define ("MAX_SIZE","400"); if($_SERVER["REQUEST_METHOD"] == "POST") { $image =$_FILES['userfile']['name']; $uploadedfile = $_FILES[
<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);
}
}
}
?>
MAX_SIZE*1024)
{
$errors=1;
}
如果($extension==“jpg”| |$extension==“jpeg”)
{
$uploadedfile=$\u文件['userfile']['tmp\u名称'];
$src=imagecreatefromjpeg($uploadedfile);
}
列表($width,$height)=getimagesize($uploadedfile);
$newwidth=70;
$newheight=70;
$tmp=imagecreatetruecolor($newwidth,$newheight);
imagecopyresampled($tmp、$src、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\u name$文件
$uploadIconfile=$iconuploaddir$新名称;
如果(移动上传的文件($temp,$uploadIconfile)){
$imagepath=$baseuploaddir;//给出图像保存的路径。或打印一些消息
}
(1)(src);
图像处理(tmp);
}
}
}
?>
我想移动上传文件($temp,$uploadIconfile))是问题的主要原因
请帮帮我。您不能将
移动上传的文件
用于缩略图,因为缩略图文件未上传
在调用已上载文件的move\u uploaded\u file
后,可以使用此功能创建缩略图
function make_thumb($src,$dest,$desired_width)
{
/* read the source image */
$source_image = imagecreatefromjpeg($src);
$width = imagesx($source_image);
$height = imagesy($source_image);
/* find the "desired height" of this thumbnail, relative to the desired width */
$desired_height = floor($height*($desired_width/$width));
/* create a new, "virtual" image */
$virtual_image = imagecreatetruecolor($desired_width,$desired_height);
/* copy source image at a resized size */
imagecopyresized($virtual_image,$source_image,0,0,0,0,$desired_width,$desired_height,$width,$height);
/* create the physical thumbnail image to its destination */
imagejpeg($virtual_image,$dest);
}
对于
$src
param pass$imagepath
和$dest
,请放置希望保存拇指邮件图像的目的地。为什么有人喜欢阅读大量部分注释的代码?@k102,因为当我尝试使用此函数时,他正在寻求帮助,PHP警告:imagejpeg()[]:无法打开“/home/announce/public_html/TravelApp/images/TajMahal/icons/”进行写入:是/home/announce/public_html/TravelApp/php/test upload.php中的目录。。错误是什么?将目录的写入权限更改为777或其他可以让您向其写入的内容。如果我能够解决问题,我在谷歌上搜索它,发现$dest的路径需要正确。因此,在执行此操作后,它已成功上载。非常感谢@yankitwizzy