Jump to content

Weird File Error


mikesena

Recommended Posts

Hi,

[CODE]if(!$mode){ $mode = "start"; }


if($mode == "start"){
    $handle = fopen($filename, "r") or die("Read: The file <i>'".$filename."'</i> could not be opened.");

    $data = fread($handle, filesize($filename)) or die("Read: The file <i>'".$filename."'</i> could not be read.");

    fclose($handle);
   

} elseif($mode == "save"){

    $handle = fopen($filename, "w") or die("Write: The file <i>'".$filename."'</i> could not be opened.");
    fwrite($handle, $data) or die("Write: The file <i>'".$filename."'</i> could not be writen.");

    fclose($handle);
   

    echo "File data saved OK!<br><br>";

   

    $handle = fopen($filename, "r") or die("Read: The file <i>'".$filename."'</i> could not be opened.");

    $data = fread($handle, filesize($filename)) or die("Read: The file <i>'".$filename."'</i> could not be read.");

    fclose($handle);

}[/CODE]

This is my php code for a basic file open / save (a section of my script).
the filename is in the style of "./" followed by the filename.
For some reason, whenever i save a file, extra slashes appear next to " and '.

eg. include('Hello.php');
    include("Hi.php");
  those would become:
    include(\'Hello.php\');
    include(\"Hi.php\");

The file contents are being displayed in a text area.  when a save button is pushed, the data is saved.

What is causing this error?
Link to comment
Share on other sites

if i'm not mistaken it's something too do with the way html passes it's form values and how magic_quotes_gpc works, (could be wrong on that)

try too remove any slashes from the filenames before they are saved,

[code]$handle = fopen(stripslashes($filename), "w")[/code]

if that works then i'd check too see what is actually being passed too $filename, making sure there are no whitespaces at the begining or end. use trim too remove any that may be there.


hope it helps

Stuie
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.