Go to
Welcome.  This is a place to get user-to-user support, learn more, and share ideas.  If you can't find your answers here, feel free to ask by creating a new topic or visit the support ticket system at :)  Have fun here!

Main Menu

Using fopen in PHP

Started by Pixel.Gnome, July 22, 2007, 01:08:39 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.


I have a PHP script, which gathers aload of content from various files, and then adds it all together, and writes a file to contain it.

When uploading to my server it does not work.... the fopen command give me a 'failed to open stream: Permission denied' message. the resutant file also cannot be written.

I am finding this most peculiar, because on the same server (different client site) I have a different script which has no problem with fopen.

does it make a difference that I uploaded the files (the entire site) from dreamweaver?


Please state whether you are using Windows or Linux server and what the permissions are on the file.


Hi. sorry - should have sad.... it's a linux server, and I set no specific permssions on the files, but upon going into the cpanel file manager, I see the directories at 755, and the files are 644. these are default settings yes?.

I am no expert at these things, but I am very wary of changing permissions (I've seen you hall of shame). I am wondering though id the 'owner' of the files / directories is different depending on weather I use the file manager to create the directories of dreamweaver etc.

I mentioned that on another site I have a script which has no problem writing to a file, but I do recall now that initially there was an issue there which I solved by having the file initially created by the script itself, however, I can't seem to get this to work for me now....

Sorry if I am making some basic errors of concept here.

thanks for the help though


You may need to set permissions on the file to 777.  I would not worry too much about security of that.  The Hall of Shame is mainly popular scripts that hackers find through google and know are exploitable.  Your setitng 777 to a specific file most likely would not offer any dangerous opportunities (database injections, cross-site scripting, etc...) for anyone.

As for the owners of the files, yes, I believe you are right.  I am not for sure, but I think that if the file is created by your FTP client, it is owned by your username.  If it is created by your FileManager, it may be owned by apache.  Thats why sometimes a CHMOD 644 (default) or 755 will do, but sometimes 777 is needed.

Hope this helps.