xx7xx7xx
xx7xx7xx

Reputation: 113

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.

This worked fine on my prior server, but on my new AWS server I guess I need permissions to write to the folder?

<?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?

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

PHP Warning: move_uploaded_file() unable to move

Upvotes: 0

Views: 1538

Answers (1)

xx7xx7xx
xx7xx7xx

Reputation: 113

My issue was I didn't have WRITE permissions on the folder, I just had 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

Understanding Linux File Permissions: https://www.linux.com/learn/tutorials/309527-understanding-linux-file-permissions

Upvotes: 1

Related Questions