|
-
Nov 18th, 2001, 09:46 PM
#1
Thread Starter
Fanatic Member
PHP, reading files, and escaping characters
I am trying to make a PHP script that lets you edit files from a web page, like Geocities. I can view the file fine, but if I save it all the quotes and backslashes get escaped. How can I prevent this?
This is the code I am using:
PHP Code:
<html>
<head>
<title>File editor</title>
<link rel="stylesheet" type="text/css" href="/main.css">
</head>
<body>
<?
$dirname = substr(strrchr(getcwd(), "\\"), 1);
$disp_name = $filename;
if ($mode == 1) {
echo "<h3>Editing: " . $disp_name . "</h3>";
$pFile = fopen($filename, "rb");
$oldContents = fread($pFile, filesize($filename));
fclose($pFile);
?>
<form method="post" action="<?=$PHP_SELF?>?filename=<?=$filename?>&mode=2">
<textarea rows="30" cols="70" name="newContents" wrap="off"><?=htmlspecialchars($oldContents)?></textarea>
<br><br>
<input type="submit" value="Save changes">
<input type="button" value="Reload file" onClick="window.location.href='edit.php?filename=<?=$filename?>&mode=1';">
<input type="button" value="Return to Index "onClick="window.location.href='index.php';">
</form>
<?
}
if ($mode == 2)
{
$pFile = fopen($filename, "wb");
fwrite($pFile, $newContents);
fclose($pFile);
echo "<h3>Saved: " . $filename . "</h3>";
?>
<form method="post" action="<?=$PHP_SELF?>?filename=<?=$filename?>&mode=2" name="a">
<textarea rows="30" cols="70" name="newContents" wrap="off"><?=$newContents?></textarea>
<br><br>
<input type="submit" value="Save changes">
<input type="button" value="Reload file"onClick="window.location.href='edit.php?filename=<?=$filename?>&mode=1';">
<input type="button" value="Return to Index "onClick="window.location.href='index.php';">
</form>
<? } ?>
</body>
</html>
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 19th, 2001, 05:07 AM
#2
Conquistador
$newContents = htmlspecialchars($newcontents);
fwrite($pFile, $newContents);
not tested but i think that should work
-
Nov 19th, 2001, 06:41 PM
#3
Thread Starter
Fanatic Member
No, doesn't work
Alcohol & calculus don't mix.
Never drink & derive.
-
Nov 20th, 2001, 06:26 PM
#4
Thread Starter
Fanatic Member
No, that doesn't work either.
Alcohol & calculus don't mix.
Never drink & derive.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|