Хорошо, так что очень простой сценарий загрузки из w3schools, я попытался реализовать, но я продолжаю получать сообщение об ошибке.move_uploaded_file() throwing error
Для справки, я использую WordPress и необходимую для создания пользовательских метод загрузки, так что я не могу использовать пользовательские поля и т.д ..
HTML раздел относительно этого:
<form method="post" id="form" enctype="multipart/form-data">
<input type="file" name="frontImage" id="frontImage">
PHP стороны вещей:
$target_dir = home_url() . "/wp-content/uploads/survey/";
$target_file = $target_dir . basename($_FILES["frontImage"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
$check = getimagesize($_FILES["frontImage"]["tmp_name"]);
if($check !== false) {
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
// Check if file already exists
if (file_exists($target_file)) {
echo "Sorry, file already exists.";
$uploadOk = 0;
}
// Check file size
if ($_FILES["frontImage"]["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["frontImage"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["frontImage"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
}
Okay s О ошибки я получаю:
"Sorry, there was an error uploading your file."
Это означает, что раздел move_uploaded_file() не удалось.
Если я print_r ($ _ FILES) я получаю:
Array
(
[frontImage] => Array
(
[name] => Everest_kalapatthar_crop.jpg
[type] => image/jpeg
[tmp_name] => /Applications/MAMP/tmp/php/phpHw9BcP
[error] => 0
[size] => 93053
)
)
Есть ли причина, почему это не работает?
Что такое * $ target_dir *? Это правильный путь к вашему каталогу? Если да, убедитесь, что разрешения для папки установлены на * 0777 * –
Вывод '$ target_dir' убедитесь, что он действителен. –
@ EM-Creations как target_dir, так и target_file являются правильными путями –