PHP move_Upload_文件已成功上载,但返回false

PHP move_Upload_文件已成功上载,但返回false,php,file-upload,image-uploading,image-upload,Php,File Upload,Image Uploading,Image Upload,我正在尝试创建一个上传到网站的图片。我还试图在写入目录之前调整图像的大小。图片上传正常,但无论出于何种原因,move_uploaded_file函数返回false,即使文件实际上正在上传。请参阅下面我的一些代码: $fileType = $_FILES['photo_one']['type']; //This gets all the other information from the form $pic=($_FILES['photo_one']['name']); $tmppic

我正在尝试创建一个上传到网站的图片。我还试图在写入目录之前调整图像的大小。图片上传正常,但无论出于何种原因,move_uploaded_file函数返回false,即使文件实际上正在上传。请参阅下面我的一些代码:

$fileType = $_FILES['photo_one']['type'];

 //This gets all the other information from the form 
 $pic=($_FILES['photo_one']['name']); 
$tmppic = ($_FILES['photo_one']['tmp_name']);
$front=uniqid (rand (),false);
$newpic=$front.'_'.$pic;
$newtmppic=$front.'_'.$tmppic;



if($fileType == 'image/jpg' || $fileType == 'image/jpeg' )
{
$tmppic = ($_FILES['photo_one']['tmp_name']);
$src = imagecreatefromjpeg($tmppic);
}
else if($fileType == 'image/png')
{
$tmppic = ($_FILES['photo_one']['tmp_name']);
$src = imagecreatefrompng($tmppic);
}
else 
{
$src = imagecreatefromgif($tmppic);
}


list($width,$height)=getimagesize($tmppic);

$newwidth='700px';
$newheight=($height/$width)*$newwidth;
$tmp=imagecreatetruecolor($newwidth,$newheight);

imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height);

 //This is the directory where images will be saved 
 $target = "../secure/profile_images/"; 
 $newtarget = $target . basename($newpic); 

imagejpeg($tmp,$newtarget,100);

 //Writes the photo to the server 
 if(move_uploaded_file($tmp, $newtarget)) 
 { 

 //Tells you if its all ok 
header('Location: Picture.php#A1');
 } 
 else { 
  //Gives an error if its not 
 echo "Sorry, there was a problem uploading your file."; 
 } 

屏幕没有重定向到Picture.php,而是返回“抱歉,上载文件时出现问题”。然而,当我在网站上查看图片时,我可以看到图像成功地存在。我检查了错误日志,但里面也没有显示任何内容,所以我不知所措。任何建议或想法都将不胜感激

问题是您使用
imagejpeg($tmp,$newtarget)
创建图像并将其存储到指定路径,然后尝试移动服务器上已创建和存储的相同文件
imagejpeg
将创建图像并将其存储在服务器上,而无需使用
move\u upload\u file
功能。如果要检查文件是否已创建,请使用以下代码删除
move\u uploaded\u file
功能

//Writes the photo to the server 
if(imagejpeg($tmp,$newtarget,100)) 
{ 

 //Tells you if its all ok 
 header('Location: Picture.php#A1');
} 
  else { 
 //Gives an error if its not 
  echo "Sorry, there was a problem uploading your file."; 
 } 

如果您使用imagick,请尝试先移动上载的文件或文件内容,然后调整图像大小,创建缩略图或修改文件,并保存您修改的副本以及mh?