我目前正在使用以下PHP脚本将图片上传到我的网络服务器。但是,这会导致许可问题,由于网络服务器访问的限制,我似乎无法改变。解决这些权限警告的最佳方法是什么?
<?php
function upload_image()
{
$target_dir = "../images/uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = true;
$imageFileType = pathinfo($target_file, PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if (isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if ($check !== false) {
$uploadOk = true;
} else {
$uploadOk = false;
return "Sorry, file is not an image.";
}
}
// Check if file already exists
if (file_exists($target_file)) {
$uploadOk = false;
return "Sorry, file already exists.";
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 200000000) {
$uploadOk = false;
return "Sorry, your file is too large.";
}
// Allow certain file formats
if ($imageFileType != "JPG" && $imageFileType != "PNG" && $imageFileType != "JPEG"
&& $imageFileType != "GIF"
) {
$uploadOk = false;
return "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == false) {
return "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
return basename($_FILES["fileToUpload"]["name"]);
} else {
return "Sorry, there was an error uploading your file.";
}
}
}