Using PHP move_uploaded_file function permission denied - php

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.

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.

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)

Related

file_put_contents failed to open stream: Permission denied

Basic php and javascript website
No errors on Wamp
When I put the files on my Lamp server everything works except for this error I get on the top of the page
Warning: file_put_contents(donneesDonut.json): failed to open stream:
Permission denied in /var/www/html/bp/action/IndexAction.php on line
101
I looked around and most people suggest to change the permission of the file or the entire directory on apache.
chmod 777 did nothing for me.
I'm new to web servers so I probably have missed some apache configuration for permissions during the installation process
Here is a screenshot of the directory
Directory listing
I don't think there is a problem with the code since it works on my local Wamp server but here is the line of code that gives me the error.
file_put_contents($this->json, json_encode($this->donneesDonut));
If you need any other information like specific apache configuration please tell me where to get them.
Hope you can help
The problem was SELinux with was set to enforce by default on Centos

PHP permissions denied failed to open stream

I have this code
<?php
$handle = fopen('names.rtf','w');
fwrite($handle, 'Alex');
?>
Warning: fopen(names.rtf): failed to open stream: Permission denied in
/Applications/XAMPP/xamppfiles/htdocs/file.php on line 3
And when I run it in comes up with that error. I've set my permissions on the folder to read & write for everyone. I'm not sure why else it would deny it.
Im using the latest Mac OS
There is possible, the issue is that your webserver or PHP instance is not running under the same user, you can check this using the get_current_user() function.
You can either configure apache to run with your privileges or give the folder more permissions, like 0777.but 0644 is enough for reading file. try to give permission according to it's usage.
Another thing, are you sure $outFile maps to an absolute path? Try doing:
var_dump(is_file("names.rtf"));

PHP File Uploading Issues

I'm trying to implement script that will allow a file to be uploaded, and then moved to a designated directory. This is running on a Windows server & IIS. I'm having 2 issues in doing so.
First, I get an error when trying to move the file.
Warning: move_uploaded_file(reports/ff.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\inetpub\wwwroot\betterinsight\betterinsight\upload_file.php on line 29
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\Windows\Temp\php1EAB.tmp' to 'reports/ff.jpg' in C:\inetpub\wwwroot\betterinsight\betterinsight\upload_file.php on line 29
Stored in: reports/ff.jpg
When searching, almost everything says it's a permission problem. I have added full rights (will pare down later) to the user: IIS_IUSRS. Even did it to the parent directory as one site recommended.
Second: As a possible solution to the above issue, I tried changing the directory in which files are saved. But the files are still uploaded into C:\windows\temp.
I've run phpinfo, and it says that uploads should be in (as defined by upload_tmp_dir):
Again, this is on a Windows Server 2008. Thanks.
Permission denied
You need to set the folder permissions to 777 or enable read write to the folder. I think the permissions are messing...
OK, the answer was simple. I was adding permissions for user: IIS_USRS, when it should have been just user: USRS.

"Unable to access" with move_uploaded_file() PHP

The function move_uploaded_file() isn't working on my server and I really dont know why.
the error:
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to access MYADDRESS/img-19.png in MYADDRESS/index.php on line 660
I gave to the folder which I upload files chmod 777. any solution? im sure 100% the problem isn't in my code.
Make sure you have it in the $src, $dest order:
move_uploaded_file($_FILES["field"]["tmp_name"], 'foo.png');
Also, check PHP settings, especially safe_mode and base dir restrictions.
Side note: Don't chmod your folders to be world writable! Change the group of the folder to be that of the webserver, and use 775. Last thing you need is something like an SQL injection from MySQL writing a PHP file into that folder.

php file manipulation functions fails on my localhost saying permission denied

im running on windows xp and i am an administrator, im using the latest xampp bundle available from their site and i receive these kinds of errors when i use file manipulation functions on php...
Warning: chmod() [function.chmod]: Permission denied in...
Warning: opendir(/feeds) [function.opendir]: failed to open dir: Permission denied in
do i need to set any environment variables for apache before i can use these functions?
but i think the problem lies only on my folder access permissions, but if so, how do i set a folder's accessibility properties on windows?
Does your php worker process have the necessary permissions?
Make sure whatever user the process is running as has proper permissions for the directory it is puking on.
right click on the folder, permissions...
it appears that my script referred to an inexistent directory as i just specified $dir='/feeds';it works fine on my machine in our office but i wonder why with the same configurations here on my pc at home it doesnt
as reference for other people who might have the same problem in the future my answer would be
check and make sure you are pointing your script to the right file :)
You can try setting the umask as well before the chmod like so;
$old_mask = umask(0);
chmod('/path/to/file', 0755);
umask($old_mask);
More information on umask can be found at PHP's Manual

Categories