ois Posted May 11, 2005 Posted May 11, 2005 I'm having trouble creating and writing a file using a very simple PHP script that I have written. I need this file to store a counter value. The file may not exist when the script runs. The code runs correctly on my local PHP installation using EasyPHP but it will not create the files on the TCH server. The main problem seems to be that I cannot actually create a file using the php function fopen("myfile.txt","w"). The most basic test was to try and create the file in the same directory as the script is running and this fopen() failed. The directory/folder does not have a .htaccess file in it and the directory is chmod to 755 to allow read/writes. I am running in a subdirectory but I don't think the root has a .htaccess file. Any suggestions would be really welcome! - Chris Quote
MikeJ Posted May 11, 2005 Posted May 11, 2005 PHP runs under the webserver user "nobody", not as your account. You will need to set the directory you want to write to as 777 so that the webserver can write to it (and for that reason I'd recommend a subdirectory, and not the directory your scripts are sitting in). Welcome to the forums, too, ois! Quote
stevevan Posted May 11, 2005 Posted May 11, 2005 Welcome to the forums! Hope Mike was able to solve your problem! Quote
ois Posted May 11, 2005 Author Posted May 11, 2005 Thanks for the clarification on the chmod (and the welcome messages). My current file placement is only for testing until I can sort this problem out, after that I'll really lock it down using subdirs and permissions. I suspected 755 might not be high enough but how can I chmod to 777? Both the Cpanel file manager and SmartFTP will let you _try_ to set 777 but always revert back to 755. It is fairly normal to restrict this to 755 with most shared hosting accounts so I figured this should work. Any other thoughts? Chris Quote
MikeJ Posted May 11, 2005 Posted May 11, 2005 Both the Cpanel file manager and SmartFTP will let you _try_ to set 777 but always revert back to 755. <{POST_SNAPBACK}> The cPanel file manager will allow you to set it to 777, but you have to do it by selecting the check boxes, not by entering the numbers (the checkboxes override the numbers). Just click the write access for group and world (you really only need world) and save. Quote
ois Posted May 11, 2005 Author Posted May 11, 2005 Mike Chmod did "take" and the script finally works with 777 permissions. Thanks for clarifying this and the quick reply. Chris Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.