gpt4 book ai didi

javascript - 无法使用 PHP 上传文件夹内的文件

转载 作者:行者123 更新时间:2023-11-28 06:28:32 24 4
gpt4 key购买 nike

我在上传项目文件夹内的文件时遇到问题。我在下面解释我的代码。

$imageName=generateRandomNumber().'_'.$_FILES["uploadme"]["name"];
$target_dir = "upload1/";
$target_file = $target_dir . basename($imageName);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$check = getimagesize($_FILES["uploadme"]["tmp_name"]);
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["uploadme"]["size"] > 500000) {
echo "Sorry, your file is too large.";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif" ) {
echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["uploadme"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["uploadme"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}

这里我获取图像并添加一个随机数,但是上传图像时无法保存在 upload1 文件夹中。这里我获取抱歉,出现错误正在上传您的文件消息。请帮助我解决此问题。

最佳答案

通过右键单击文件夹并选择权限选项卡授予文件夹权限,然后通过允许在文件夹中创建和删除文件来授予文件夹权限。

关于javascript - 无法使用 PHP 上传文件夹内的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34899406/

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