我在项目文件夹中上传文件时遇到问题。我正在解释下面的代码。
$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
文件夹中。我收到Sorry, there was an error uploading your file
消息。请帮我解决这个问题。
答案 0 :(得分:0)
通过右键单击文件夹并选择权限选项卡来授予文件夹权限,然后通过允许从文件夹创建和删除文件来授予文件夹权限。