У меня проблема с загрузкой файлов через PHP. Я знаю, что были похожие темы, но я не мог решить свою проблему. Что не так в этом коде? Может быть, что-то о функции move_uploaded_file ()? Или, может быть, файл разрешения? Я не могу изменить атрибут «Только чтение» («Tylko do odczytu ...»).
Вот разрешения для файлов:
![](https://i.stack.imgur.com/7TOAo.png)
Вот мой код:
<?php
$upload_errors = array(
UPLOAD_ERR_OK => "There is no error, the file uploaded with success.",
UPLOAD_ERR_INI_SIZE => "The uploaded file exceeds the upload_max_filesize directive in php.ini.",
UPLOAD_ERR_FORM_SIZE => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.",
UPLOAD_ERR_PARTIAL => "The uploaded file was only partially uploaded.",
UPLOAD_ERR_NO_FILE => "No file was uploaded.",
UPLOAD_ERR_NO_TMP_DIR => "Missing a temporary folder.",
UPLOAD_ERR_CANT_WRITE => "Failed to write file to disk.",
UPLOAD_ERR_EXTENSION => "A PHP extension stopped the file upload."
);
$temp_name = $_FILES['file_upload']['$temp_name'];
$the_file = $_FILES['file_upload']['$name'];
$directory = "uploads";
if ( move_uploaded_file( $temp_name, $directory . "/" . $the_file ) ) {
$the_message = "File uploaded successfully";
} else {
$the_error = $_FILES['file_upload']['error'];
$the_message = $upload_errors[$the_error];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Document</title>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<h2>
<?php
if( !empty($upload_errors) ) {
echo $the_message;
}
?>
</h2>
<input type="file" name="file_upload" value=""><br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>
Спасибо за помощь! :)