0

I've used move_uploaded_file successfully in the past, however I'm having an issue with permissions I believe with a new server I'm testing this on. I've created a folder named "uploads" for the uploads to be moved to via FTP. Here's a screenshot showing the permissions:

enter image description here

Everyone has read/write access, but when I upload a file I'm getting an error on the line that moves the file to the "uploads" directory:

if (move_uploaded_file($_FILES['photo1']['tmp_name'], $upload_directory.$uploadedFile)) {

The file is not moved to the "uploads" folder and looking at the server log I can see entries like this:

php[1344] PHP Warning: move_uploaded_file(uploads/2.jpg): failed to open stream: Permission denied in C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\test_upload\index.php on line 206 PHP Warning: move_uploaded_file(): Unable to move 'C:\Windows\Temp\php2D93.tmp' to 'uploads/2.jpg' in C:\Program Files\FileMaker\FileMaker Server\HTTPServer\conf\ test_upload\index.php on line 206

I can't see how it can be a permissions issue if all users have read/write/execute on the "uploads" folder? Here are the variables:

$upload_directory='uploads/'; $uploadedFile= $_FILES['photo1']['name'];

user982124
  • 4,416
  • 16
  • 65
  • 140
  • Possible duplicate of [move\_uploaded\_file gives "failed to open stream: Permission denied " error after all configurations i did](http://stackoverflow.com/questions/8103860/move-uploaded-file-gives-failed-to-open-stream-permission-denied-error-after) – PseudoAj May 23 '16 at 01:56
  • Can you please display all variables? :) – GROVER. May 23 '16 at 02:09
  • @CaelanGrgurovic I've updated with the variables and full PHP error log entries – user982124 May 23 '16 at 03:08
  • Possible duplicate of [Failed to open stream : No such file or directory](http://stackoverflow.com/questions/36577020/failed-to-open-stream-no-such-file-or-directory) – Vic Seedoubleyew May 27 '16 at 21:36

2 Answers2

0

It appears that uploads/2.jpg is $_FILES['photo1']['tmp_name'] and should therefore have been uploaded to the server's /tmp/ directory. On most systems, because /tmp is a system dir, it has restricted permissions on it.

See if you can alter the perms on /tmp or find out exactly which dir the tmp uploaded file is being moved to first, before being "uploaded" (and then alter the perms on that dir).

Regardless, the path to the file as passed to move_uploaded_file() doesn't look right. It needs to be a full-path. Possibly the server-error you're seeing is not happening at precisely the same time as the upload operation takes place.

theruss
  • 1,690
  • 1
  • 12
  • 18
  • Sorry my PHP errors didn't paste in correctly - have updated. As you can see the file is uploaded correctly, e.g. C:\Windows\Temp\php2D93.tmp, it just can't move to the uploads folder. – user982124 May 23 '16 at 03:07
  • 1
    Yeah but PHP needs to be able to read the source file: `C:\Windows\Temp\php2D93.tmp` so I'd check the webserver running PHP has permission to read _that_ folder. – theruss May 23 '16 at 04:08
0

I wasn't able to fix this via FTP settings. I had to adjust the settings by logging in to the Windows Server and changing the security settings on the folder I was trying to move files into so that the "Users" had read/write access.

user982124
  • 4,416
  • 16
  • 65
  • 140