0

I've been stuck on this code for days as I am hitting this error when I upload a file to the server. Its a windows server running on Apache

Tried various solutions but still receiving the error. I tried changing full permissions to everyone on that server.

I changed the default PHP upload tmp file to inside my application yet I am still having this error.

Warning: move_uploaded_file(C:\My_Workspace\ojs2002) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\My_Workspace\ojs\admin\include\fileupload.php on line 78

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\My_Workspace\ojs\tmp\phpCB78.tmp' to 'C:\My_Workspace\ojs2002' in C:\My_Workspace\ojs\admin\include\fileupload.php on line 78

 // copy the file, making the destination directory if necessary
 $filedir = 'C:/My_Workspace/ojs2002/'.basename($_FILES['articlefile']['name']);


 chmod($_FILES["articlefile"]["tmp_name"], 0777);
 chmod($filedir, 0777 );        

 move_uploaded_file($_FILES["articlefile"]["tmp_name"],$filedir);

The code would work fine on Linux servers but not on Windows.

Any help would be very much appreciated. Thank You.

2 Answers2

1

I decided to switch from:

move_uploaded_file($uploaded_file, $file_path);

to

file_put_contents($file_path, file_get_contents($uploaded_file));
@unlink($uploaded_file);

The unlink might fail but I'm not too worried about that.

pguardiario
  • 53,827
  • 19
  • 119
  • 159
0

chmod won't work on Windows, as it uses a different type of permission system. Make sure the user Apache runs as has full write access to the folder you're trying to move the files to (right click and click on sharing or permissions depending on the version of windows)

Lusitanian
  • 11,012
  • 1
  • 41
  • 38
  • How do I find out what user is Apache is using to create/move folders on Windows ?? I am using Windows 7. Thanks – Steven Tang Ti Khoon Jul 07 '12 at 02:21
  • @StevenTangTiKhoon follow [these instructions](http://answers.microsoft.com/en-us/windows/forum/windows_vista-files/how-do-i-change-folder-and-file-permissions/465f2b42-63dd-4486-8dd1-c870290efeed). It's for vista, but should be roughly the same. Just set `Everyone` to full control and see if it works :) – Lusitanian Jul 07 '12 at 02:22
  • Hi i have already set perms for folder to Everyone http://imageshack.us/photo/my-images/69/772012115225am.jpg/ ...still having the error :( – Steven Tang Ti Khoon Jul 07 '12 at 03:55