View Full Version : fopen() permission error
Hi. I have a script that uses fopen() to open and make changes to other files on the server. I developed the script, tested it on one server, and it worked great. However, I tried it on another server and I get:
Warning: fopen(/path/to/file.htm): failed to open stream: Permission denied in /path/to/script.php on line 316
(Obviously the paths are changed for simplicity/security)
Is this a problem with my php, or server config? I contacted the host and - after convincing them my code was valid - they told me I had to chmod everything to 666. The thing is, this worked on the first host with no problems at 644. HELP! If this is not a php issue, please point me in the right direction (or you could help anyway, which would be great...)
09-03-2005, 03:27 AM
It's not a php issue, but like your host said, a permissions issue. If 0644 doesn't work, then try 0777 (think that one's right)
09-03-2005, 06:41 AM
That's permission issue.
777 will solve the problem but try to limit cause fopen() don't need write permission :o
09-03-2005, 09:04 AM
fopen may need chmod including write permissions however.
If 0644 doesn't work for you, attempt a 0700 instead. If neither work for you, you need alternative means for this, as your host doesn't allow the use of file opening via php. Some means may include XML or curl.
Thanks for the suggestions. Two important characteristics of this project:
1) It is a CMS for a non-technical user (no idea about chmod)
2) Being a CMS, it will need to access almost all the files on the server (about 200+ so far, and growing)
That said, is having to chmod every existing file now and every new file in the future really an ideal solution? Can I ask the host to change the owner of the files or something? I would think it would be easy for them to change a server config somehow to allow this, as like I said it works at 644 with another host. I am not that familair with working with hosts, so I don't know if that type of mod is feasible or an acceptable request of them.
I have heard about curl, but that's about it. I'd have to do some serious reading and probably have to completely revamp my code?
09-03-2005, 06:46 PM
chmod can be done at script process. The function chmod() will do the trick for you in this case. If your filepermissions are not a problem, then its a limitation of your host, which means that using an alternative method will be in store. Yes, curl will be an option, and will require alterations for your current methods in order to work.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.