Renidrag Posted February 20, 2009 Share Posted February 20, 2009 I know, another fopen question - but this one is stumping me server isn't in safe mode, fopen is allowed, directory set to 777, and file to 777 - I can open and read and display the contents of a file but i can not open for "w" writing what else causes the fopen not to open a file with write capabilities? basically i just want to open a file from a custom back end section of my website, i want to display this content in a text box, edit it and have the contents of the file on submit saved to the file so on submit i go to open the file and it will not open for writing. any input is good, thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/ Share on other sites More sharing options...
PFMaBiSmAd Posted February 20, 2009 Share Posted February 20, 2009 Add the following two lines of code immediately after your first opening <?php tag to show all php generated errors - ini_set ("display_errors", "1"); error_reporting(E_ALL); You would need to post your code to get any help with what it might be doing that is not working. Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767071 Share on other sites More sharing options...
Mad Mick Posted February 20, 2009 Share Posted February 20, 2009 How do you mean "will not open for writing". The 'w' will helpfully wipe the file first. Maybe you want 'a' for append? Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767091 Share on other sites More sharing options...
Renidrag Posted February 21, 2009 Author Share Posted February 21, 2009 sorry should have put the code here in the first place [pre]<?php ini_set ("display_errors", "1"); error_reporting(E_ALL); $loadcontent = $_GET['a']; if(isset($_POST['btnSave'])){ $savecontent = stripslashes($_POST['content']); clearstatcache(); ignore_user_abort(true); ## prevent refresh from aborting file operations and hosing file $fh = fopen($loadcontent, 'a'); ## use 'r+b' so file can be read and written if($fh){ if(flock($fh, LOCK_EX)) ## don't do anything unless lock is successful { $count = fread($fh, filesize($loadcontent)); rewind($fh); fwrite($fh, $savecontent); fflush($fh); ftruncate($fh, ftell($fh)); ## better than truncating to 0 before writing, per 04-Mar-2003 comment below flock($fh, LOCK_UN); }else{ echo "Could not lock current file '$loadcontent'<br />"; echo "<a href='cms_edit.php?a=" . $_GET['a'] . "&link=static'>click here to go back now</a>"; } fclose($fh); }else{ echo "<br />Could not open current file '$loadcontent'<br />"; echo "<a href='cms_edit.php?a=" . $_GET['a'] . "&link=static'>click here to go back</a>"; } ignore_user_abort(false); ## put things back to normal } ?>[/pre] Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767578 Share on other sites More sharing options...
haku Posted February 21, 2009 Share Posted February 21, 2009 So what is the error? And are you sure that 'a' is set in your URL? Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767725 Share on other sites More sharing options...
Renidrag Posted February 21, 2009 Author Share Posted February 21, 2009 the $_GET['a'] is the name of the file to be open for writting to - in the page before it the file does get open with fopen("filename", "r") and it works fine - the content of the page gets diplayed on the page, then i make changes to it and click submit the next page opens the file (from beginning) and over writes the old content with the new content at least that is what it suppose to do but on the follow-up page the file will not open with fopen("filename", "w") or "a" or "r+" or "w+" Warning: fopen(banner_con1.php) [function.fopen]: failed to open stream: Permission denied in /home/xxxxxxxxx/public_html/dev3/xxxxxxxxx_edit.php on line 10 says permission denied, but as i mentioned above folder is set to 777 and file is set to 777 and php is not in safe mode and fopen shows as allowed in phpinfo() Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767837 Share on other sites More sharing options...
haku Posted February 21, 2009 Share Posted February 21, 2009 Add this: die('loadcontent is: ' . $loadcontent . '.'); before this: $fh = fopen($loadcontent, 'a'); And make sure that it is set. Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767843 Share on other sites More sharing options...
Renidrag Posted February 21, 2009 Author Share Posted February 21, 2009 Add this: die('loadcontent is: ' . $loadcontent . '.'); before this: $fh = fopen($loadcontent, 'a'); And make sure that it is set. put that in, and yes it comes back with the page name to open Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767868 Share on other sites More sharing options...
haku Posted February 21, 2009 Share Posted February 21, 2009 Everything looks right to me then. You should maybe contact your hosting company. It doesn't really make sense that it wouldn't work even with the chmod set to 777. Maybe they have something set on the backend. Quote Link to comment https://forums.phpfreaks.com/topic/146117-fopen-question/#findComment-767885 Share on other sites More sharing options...
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.