简体   繁体   English

PHP文件上传问题-无法上传到所需文件夹

[英]PHP File Upload Issues - Can't Upload to Desired Folder

I get a $tmp_name of "/tmp/phpv1K2Eh" but I can't move the temporary file to the "uploads/" folder. 我得到的$ tmp_name为“ / tmp / phpv1K2Eh”,但无法将临时文件移至“ uploads /”文件夹。

This worked fine on my prior server, but on my new AWS server I guess I need permissions to write to the folder? 这在我之前的服务器上运行良好,但是在我的新AWS服务器上,我想我需要写入该文件夹的权限?

<?php

$name =         $_FILES['file']['name'];
$tmp_name =     $_FILES['file']['tmp_name'];

if(isset($name) && !empty($name)){

    $location = 'uploads/' .$name;

    if(move_uploaded_file($tmp_name, $location)){
        echo 'File Uploaded!';
    } else {
        echo 'Error in upload';
    }

}
?>

<form action="test.php" method="POST" enctype="multipart/form-data">
    <input type="file" name="file"><br><br>
    <input type="submit" name="Submit">
</form>

EDIT: Needed to grant upload permissions to the folder. 编辑:需要授予该文件夹的上传权限。 But how do I do this for all folders and subfolders in /var/www? 但是,如何对/ var / www中的所有文件夹和子文件夹执行此操作?

$ sudo chown apache:apache /var/www/html/uploads/

PHP Warning: move_uploaded_file() unable to move PHP警告:move_uploaded_file()无法移动

My issue was I didn't have WRITE permissions on the folder, I just had READ & EXECUTE. 我的问题是我没有对该文件夹的WRITE权限,我只有READ&EXECUTE。 This creates write permissions for the "uploads" folder and all its subfolders: 这将为“上载”文件夹及其所有子文件夹创建写许可权:

sudo chmod -R ugo+rw /var/www/html/uploads

Main source for my answer: https://www.linux.com/learn/tutorials/760276-how-to-manage-file-and-folder-permissions-in-linux 我的答案的主要来源: https : //www.linux.com/learn/tutorials/760276-how-to-manage-file-and-folder-permissions-in-linux

Understanding Linux File Permissions: https://www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions 了解Linux文件权限: https : //www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM