mikesena Posted August 25, 2006 Share Posted August 25, 2006 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 https://forums.phpfreaks.com/topic/18634-weird-file-error/ Share on other sites More sharing options...
Stuie_b Posted August 25, 2006 Share Posted August 25, 2006 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 helpsStuie Link to comment https://forums.phpfreaks.com/topic/18634-weird-file-error/#findComment-80291 Share on other sites More sharing options...
shocker-z Posted August 25, 2006 Share Posted August 25, 2006 you need to use stripslashes()EDIT: oops u had an _ in the functionBasicaly you need to use stripslashes($inputvariable);and that will remove all \ from the variable. Link to comment https://forums.phpfreaks.com/topic/18634-weird-file-error/#findComment-80294 Share on other sites More sharing options...
kenrbnsn Posted August 25, 2006 Share Posted August 25, 2006 Trimming doesn't remove backslashes, it removes characters (usually whitespace and newline) from the beginning and end of values. You need to use the functions stripslashes() on the value.Ken Link to comment https://forums.phpfreaks.com/topic/18634-weird-file-error/#findComment-80295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.