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.
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)
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.