Jump to content

fopen Question


Renidrag

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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]

Link to comment
Share on other sites

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()

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.