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.<br /><br />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. <br /><br />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.<br /><br />Any suggestions would be really welcome!<br /><br />- Chris<!--content-->
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).<br /><br />Welcome to the forums, too, ois!<!--content-->
Welcome to the forum, ois. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
Welcome to the forums ois <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/kicking.gif" style="vertical-align:middle" emoid=":dance:" border="0" alt="kicking.gif" /><!--content-->
Welcome to the forums! Hope Mike was able to solve your problem!<!--content-->
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.<br /><br />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.<br /><br />Any other thoughts?<br /><br />Chris<!--content-->
<!--QuoteBegin-ois+May 11 2005, 12:16 PM--><div class='quotetop'>QUOTE(ois @ May 11 2005, 12:16 PM)</div><div class='quotemain'><!--QuoteEBegin-->Both the Cpanel file manager and SmartFTP will let you _try_ to set 777 but always revert back to 755. <div align="right"><a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=129578"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />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.<!--content-->
Mike<br /><br />Chmod did "take" and the script finally works with 777 permissions.<br /><br />Thanks for clarifying this and the quick reply.<br /><br />Chris<!--content-->
Welcome to the forums Chris <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid="" border="0" alt="biggrin.gif" /><!--content-->
Welcome to the forums, Chris! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->
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).<br /><br />Welcome to the forums, too, ois!<!--content-->
Welcome to the forum, ois. <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid="" border="0" alt="smile.gif" /><!--content-->
Welcome to the forums ois <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/kicking.gif" style="vertical-align:middle" emoid=":dance:" border="0" alt="kicking.gif" /><!--content-->
Welcome to the forums! Hope Mike was able to solve your problem!<!--content-->
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.<br /><br />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.<br /><br />Any other thoughts?<br /><br />Chris<!--content-->
<!--QuoteBegin-ois+May 11 2005, 12:16 PM--><div class='quotetop'>QUOTE(ois @ May 11 2005, 12:16 PM)</div><div class='quotemain'><!--QuoteEBegin-->Both the Cpanel file manager and SmartFTP will let you _try_ to set 777 but always revert back to 755. <div align="right"><a href="http://www.totalchoicehosting.com/forums/index.php?act=findpost&pid=129578"><img src='http://www.totalchoicehosting.com/forums/style_images/1/post_snapback.gif' alt='*' border='0' /></a></div><!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />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.<!--content-->
Mike<br /><br />Chmod did "take" and the script finally works with 777 permissions.<br /><br />Thanks for clarifying this and the quick reply.<br /><br />Chris<!--content-->
Welcome to the forums Chris <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/biggrin.gif" style="vertical-align:middle" emoid="" border="0" alt="biggrin.gif" /><!--content-->
Welcome to the forums, Chris! <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/thumbup1.gif" style="vertical-align:middle" emoid=":thumbup1:" border="0" alt="thumbup1.gif" /><!--content-->