usa*_*ama 1 php xampp file-io file-upload
这是两个错误
警告:move_uploaded_file(/uploads53e866b24977d1.48375376.pdf):无法打开流:权限在第28行的C:\ xampp \ htdocs \ file_upload \ upload.php中被拒绝
警告:move_uploaded_file():无法在第28行的C:\ xampp \ htdocs \ file_upload \ upload.php中将“ C:\ xampp \ tmp \ php7D69.tmp”移动到“ /uploads53e866b24977d1.48375376.pdf”
这是我的HTML
<form method="POST" action="upload.php" enctype="multipart/form-data">
<label for="">Upload Your Cv</label><input type="file" name="file">
<input type="submit" value="upload">
</form>
Run Code Online (Sandbox Code Playgroud)
这是我的PHP
if (isset($_FILES['file'])) {
$file = $_FILES['file'];
// print_r($file); just checking File properties
// File Properties
$file_name = $file['name'];
$file_tmp = $file['tmp_name'];
$fiel_size = $file['size'];
$file_error = $file['error'];
// Working With File Extension
$file_ext = explode('.', $file_name);
$file_fname = explode('.', $file_name);
$file_fname = strtolower(current($file_fname));
$file_ext = strtolower(end($file_ext));
$allowed = array('txt','pdf','doc');
if (in_array($file_ext,$allowed)) {
if ($file_error === 0) {
if ($fiel_size <= 5000000) {
// $file_name_new = $file_fname . uniqid('',true) . '.' . $file_ext;
$file_name_new = uniqid('',true) . '.' . $file_ext;
$file_destination = '/uploads' . $file_name_new;
// echo $file_destination;
if (move_uploaded_file($file_tmp, $file_destination)) {
echo "Cv uploaded";
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
小智 5
SELinux可能阻止了文件的写入。如果是这种情况,则应将文件的上下文更改为httpd_sys_rw_content_t,这意味着它将变为Apache所使用的可读可写目录和文件。
将此分配给应用程序可以在其中创建或修改文件的目录,或者将其分配给files目录以允许您的应用程序对其进行修改。
sudo chcon -t httpd_sys_rw_content_t /var/www/html/path/to/writable/folder -R
Run Code Online (Sandbox Code Playgroud)