Wrong file permissions

Fix to unable to delete file from FTP server after uploading using PHP function move_uploaded_file.
I was struggling with this for a while, I have a PHP script to upload a file to a web space (Uploadifive library), works perfect with nice ajax and bootstrap UI, however, that script somehow prevents me from deleting file just uploaded.

This is mostly because in Windows Server, PHP function inherits the permission of the temp folder when moves files from temp folder to final destination.

Found it somewhere online ...


Public

Tested

My Own Work
Use chmod to change file attributes after uploading

if (in_arrayi($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile, $targetFile);
        chmod($targetFile, 0777); // Added 2020-12-17 to go around the fact that we cannot delete file after we uploaded it
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
?>

Views 559 Downloads 207

PHP File System
ANmarAmdeen
813
Attachments
Revisions

v1.0