gpt4 book ai didi

php - 在php中上传文件时发生错误(图片)

转载 作者:行者123 更新时间:2023-11-29 21:42:02 28 4
gpt4 key购买 nike

首先我想对这个问题表示歉意,因为我知道已经有很多人问过这个问题了。但我搜索的所有答案都没有解决我的问题。所以希望您考虑这个问题并帮助我解决这个问题。

所以基本上我正在尝试上传图像文件,当我提交它时,会弹出错误:

Warning: move_uploaded_file(./images/jarvs.jpg): failed to open stream:

Warning: move_uploaded_file(): Unable to move 'C:\wamp\tmp\phpA25F.tmp' to './images/jarvs.jpg'

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

这是我的代码:

HTML: <input id="profimagefile" name="profileimage" class="input-file" type="file">

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/";
//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/>";
}

关于php - 在php中上传文件时发生错误(图片),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34412046/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com