在php中上载文件时出错(图像)

在php中上载文件时出错(图像),php,html,mysql,Php,Html,Mysql,首先,我想为这个问题道歉,因为我知道已经有很多人在问这个问题了。但我搜索的所有答案都没有解决我的问题。所以希望你能考虑这个问题并帮助我解决这个问题。 因此,基本上我正在尝试上载一个图像文件,当我提交它时,会弹出错误: 警告:移动上传的文件(./images/jarvs.jpg):无法打开流: 警告:移动上传的文件():无法将“C:\wamp\tmp\phpA25F.tmp”移动到“./images/jarvs.jpg” 我真的没有得到错误,但我知道错误发生时,我试图从图像的路径传输图像,并将其发

首先,我想为这个问题道歉,因为我知道已经有很多人在问这个问题了。但我搜索的所有答案都没有解决我的问题。所以希望你能考虑这个问题并帮助我解决这个问题。 因此,基本上我正在尝试上载一个图像文件,当我提交它时,会弹出错误:

警告:移动上传的文件(./images/jarvs.jpg):无法打开流:

警告:移动上传的文件():无法将“C:\wamp\tmp\phpA25F.tmp”移动到“./images/jarvs.jpg”

我真的没有得到错误,但我知道错误发生时,我试图从图像的路径传输图像,并将其发送到我的目标文件夹(目标路径)

这是我的密码:

HTML:

PHP:

$targetPath = "images/";
$targetPath = $targetPath.basename($_FILES['profileimage']['name']);

 //name of the file
 $img = $_FILES['profileimage']['name'];
 $size = $_FILES['profileimage']['size'];
 $type = $_FILES['profileimage']['type'];

 if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath))
 {
 $queryupload = "INSERT INTO images_profile (image_name, image_path, date_uploaded, emailAddress)
  VALUES ('$img', '$targetPath','$registerDate', '$email')";

 mysqli_query($conn, $queryupload);
 echo "The file ". basename($_FILES['profileimage']['name']). " has been uploaded." . "<br/>";
 }
 else {
 echo "Sorry, there was a problem uploading your file." . "<br/>";
 }
$targetPath=“images/”;
$targetPath=$targetPath.basename($_文件['profileimage']['name']);
//文件名
$img=$_文件['profileimage']['name'];
$size=$\u文件['profileimage']['size'];
$type=$\u文件['profileimage']['type'];
如果(移动上传的文件($文件['profileimage']['tmp\U名称'],$targetPath))
{
$queryupload=“插入图像\配置文件(图像\名称、图像\路径、上载日期\电子邮件地址)
值(“$img”、“$targetPath”、“$registerDate”、“$email”);
mysqli_查询($conn,$queryupload);
回显“文件”.basename($_FILES['profileimage']['name'])。”已上载。“
”; } 否则{ echo“抱歉,上载文件时出现问题。”。“
”; }
不要介意插入数据库,它只是图像已经移动到我的targetpath后过程的一部分。 谢谢你的回答。试试这个:

HTML

<form enctype="multipart/form-data>
<input id="profimagefile" name="profileimage" class="input-file" type="file">
</form>
试试这个

$targetPath = "images/";
//create folder if not exist
if(!is_dir($targetPath)){
    if(!mkdir($targetPath, 0777, true)){
        die('Failed to create folder.');
    }   
}
//set folder's permissions writale and executable
chmod($targetPath, 0777);
$targetPath = $targetPath.basename($_FILES['profileimage']['name']);

 //name of the file
 $img = $_FILES['profileimage']['name'];
 $size = $_FILES['profileimage']['size'];
 $type = $_FILES['profileimage']['type'];

 if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath))
 {
 $queryupload = "INSERT INTO images_profile (image_name, image_path, date_uploaded, emailAddress)
  VALUES ('$img', '$targetPath','$registerDate', '$email')";

 mysqli_query($conn, $queryupload);
 echo "The file ". basename($_FILES['profileimage']['name']). " has been uploaded." . "<br/>";
 }
 else {
 echo "Sorry, there was a problem uploading your file." . "<br/>";
 }
$targetPath=“images/”;
//创建文件夹(如果不存在)
如果(!is_dir($targetPath)){
如果(!mkdir($targetPath,0777,true)){
die('创建文件夹失败');
}   
}
//设置文件夹的可写和可执行权限
chmod($targetPath,0777);
$targetPath=$targetPath.basename($_文件['profileimage']['name']);
//文件名
$img=$_文件['profileimage']['name'];
$size=$\u文件['profileimage']['size'];
$type=$\u文件['profileimage']['type'];
如果(移动上传的文件($文件['profileimage']['tmp\U名称'],$targetPath))
{
$queryupload=“插入图像\配置文件(图像\名称、图像\路径、上载日期\电子邮件地址)
值(“$img”、“$targetPath”、“$registerDate”、“$email”);
mysqli_查询($conn,$queryupload);
回显“文件”.basename($_FILES['profileimage']['name'])。”已上载。“
”; } 否则{ echo“抱歉,上载文件时出现问题。”。“
”; }
您是否已授予文件夹权限?请检查“图像/”文件夹的权限什么权限?我不明白。@JarvisMillan文件夹
/images/
首先存在吗?然后,列出directoy结构(
ls-lai
在Unix系统上),并将结果打印到您的问题中。使用绝对路径而不是./images/jarvs.jpgnope,它使我想到了else语句,没有转到文件\u existsAdd在else echo error num中添加此行:“.$\u FILES['profileimage'][“error”];你上传文件时收到错误代码了吗?。如果文件完全上传$_FILES['profileimage'][“error”]将为零,它只给了我“0”-。$_FILES['profileimage'][“error”];我现在明白了为什么它给了我一个错误,因为实际上我的图像文件夹与我的php文件不在同一个目录中。我的图像文件夹位于:“public/images”而我的php文件位于:“public/php/saveimage.php”
$targetPath = "images/";
//create folder if not exist
if(!is_dir($targetPath)){
    if(!mkdir($targetPath, 0777, true)){
        die('Failed to create folder.');
    }   
}
//set folder's permissions writale and executable
chmod($targetPath, 0777);
$targetPath = $targetPath.basename($_FILES['profileimage']['name']);

 //name of the file
 $img = $_FILES['profileimage']['name'];
 $size = $_FILES['profileimage']['size'];
 $type = $_FILES['profileimage']['type'];

 if(move_uploaded_file($_FILES['profileimage']['tmp_name'], $targetPath))
 {
 $queryupload = "INSERT INTO images_profile (image_name, image_path, date_uploaded, emailAddress)
  VALUES ('$img', '$targetPath','$registerDate', '$email')";

 mysqli_query($conn, $queryupload);
 echo "The file ". basename($_FILES['profileimage']['name']). " has been uploaded." . "<br/>";
 }
 else {
 echo "Sorry, there was a problem uploading your file." . "<br/>";
 }