Thursday, February 3, 2022

[SOLVED] File Permissions Using Dropzone.js

Issue

When I upload files to my uploads directory using dropzone.js, they are automatically assigned a read-only status. The uploads directory and the actions directory where the file upload is executed (I'm using symfony 1.4 in centOS 7) have drwxrwxrwx and drwxrwxrwx. permissions respectively. I am also the owner of the directories.

How do I asynchronously assign files rwx permission after they are uploaded using dropzone.js?

File upload action:

$ds          = DIRECTORY_SEPARATOR;  //1

$storeFolder = '../uploads';   //2

if (!empty($_FILES)) {

    $tempFile = $_FILES['file']['tmp_name'];          //3

    $targetPath = dirname( __FILE__ ) . $ds. $storeFolder . $ds;  //4

    $targetFile =  $targetPath. $_FILES['file']['name'];  //5

    move_uploaded_file($tempFile,$targetFile); //6

    $this->redirect('beep/boop?id=' . $goop);
}

Solution

    ...
    /**
     * Set file permissions after moving it to target folder
     */
    chmod($targetFile, 0700); //rwx only for owner 
    ...


Answered By - waldek_h
Answer Checked By - Willingham (WPSolving Volunteer)