Solved

PHP Warning: file_put_contents permission denied for directory

Posted on 2010-11-18
8
3,423 Views
Last Modified: 2013-11-19
I am about to pull my hair out on this issue. I have written a mail checking script which checks our mail server (hosted remotely) and it needs to download attachments and copy them to a directory on my local intranet web server.

The script is properly going through mail, the problem is the attachments. I cannot seem to gain permissions to the directory to create a file there.

Here is the error I am getting:

PHP Warning: file_put_contents(scans/10-4194.txt) [function.file-put-contents]: failed to open stream: Permission denied in C:\inetpub\wwwroot\quotation_test\log\log_mailcheck.php on line 107

I am running IIS 7 and PHP 5.2

Safe modes in PHP are already turned off (I heard this could cause issue). I have already go into Windows via IIS and the Explorer to check the Permissions for the "scans" directory. IIS_IUSERS is set to Allow for everything.

What could I be missing? Thanks in advance.

Jen
0
Comment
Question by:gfei
  • 4
  • 4
8 Comments
 
LVL 2

Expert Comment

by:schwomp
ID: 34167306
Hello!

Check your open_basedir directive in php.ini.

Does the directory C:\inetpub\wwwroot\quotation_test\log\scans exists ?

Maybe it could be easier to find a solution if you post your code, . ;)

Bye.
0
 

Author Comment

by:gfei
ID: 34168785
I will resume this on Monday at the office. I will update when I can get on my computer there. Thanks in advance.
0
 
LVL 2

Expert Comment

by:schwomp
ID: 34170958
You welcome!
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 

Author Comment

by:gfei
ID: 34188299
Okay, I am back in the office.

open_basedir is commented out in PHP.INI file. Should this be changed?

This is the line of code I am using as test line to see if I can at least get the function working:

file_put_contents("scans/".$fileName.".txt", "test data");

and it returns this error:
PHP Warning: file_put_contents(scans/10-4194.txt) [function.file-put-contents]: failed to open stream: Permission denied in C:\inetpub\wwwroot\quotation_test\log\log_mailcheck.php on line 107

0
 
LVL 2

Accepted Solution

by:
schwomp earned 500 total points
ID: 34191815
Hum....

var_dump ( is_writable ( "scans/" ) );

if it returns false, you have a permission problem with the directory.

Try a chmod ( "scans/", 777 );

Bye.
0
 

Author Comment

by:gfei
ID: 34192795
All right, schwomp, I will give you the points because in theory, your answer was correct and will probably help someone. That directory was not writable. I am not sure if that chmod command would have fixed it though.

The problem was more in-depth and required a permissions reset of the directory in IIS, along with giving the directory permissions using the Security tab in Windows.
0
 

Author Closing Comment

by:gfei
ID: 34192802
This solution would help someone who did not have an issue with IIS permissions. So, I will award the points to the responder.
0
 
LVL 2

Expert Comment

by:schwomp
ID: 34194403
> The problem was more in-depth and required a permissions reset of the directory in IIS, along with giving the directory permissions using the Security tab in Windows.

Sorry, I did not pay attention to the fact that you were using Windows...

nevertheless, thanks for the points!

Bye
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

"In order to have an organized way for empathy mapping, we rely on a psychological model and trying to model it in a simple way, so we will split the board to three section for each persona and a scenario and try to see what those personas would Do,…
Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…

821 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question