Uploaded files receiving incorrect permissions
Posted by zz-James Moir on 21 June 2016 04:07 PM


When uploading files to a Unix server, you may receive errors about file permissions similar to these below.

Warning: move_uploaded_file(<Filename>) [function.move-uploaded-file]:
failed to open stream: Permission denied in <PathToYourScript> on line XXX

Warning: move_uploaded_file() [function.move-uploaded-file]:
Unable to move '<TemporaryFilename' to '<Filename>' in <PathToYourScript> on line XXX


This results from a bug in the way the CGI version of PHP (which we use for enhanced security) handles permissions when using the move_uploaded_file function.


There is no solution at present however we do offer a workaround.

For all instances where the move_uploaded_file function is being used, insert a chmod function immediately after the function. See the example below

      # Code that follows a successful upload;
       #Code to handle move_uploaded_file function error;