Jump to content

File Editor Help


marcus

Recommended Posts


I made a file editor, the only problem is that, when I try to change the file contents it just added that content I changed it to the actual file content.

 

Say:

 

if file abc.php's content was:

 

hello

 

and i wanted to change the WHOLE file to say goodbye and when I hit save, it would make the contents:

 

hellogoodbye

 

CODE:

 

edit.php

 

<?php


$loadcontent = $_GET['page'];



if ( isset ( $_POST['savecontent'] ) && trim ( $_POST['savecontent'] ) != '' )
{

$content = $_POST['savecontent'];

$fp = @fopen ( $loadcontent, 'w' );
if ( $fp )
{
	fwrite ( $fp, $content );
	fclose ( $fp );
}
}
else
{
$fp = @fopen ( $loadcontent, 'r' );
$content = htmlspecialchars ( fread ( $fp, filesize ( $loadcontent ) ) );
fclose ( $fp );
}

?>
<form method=post action="change.php">
<input type=hidden name=filename value="<?=$_GET

?>">
savecontent
<textarea name="theText" cols="70" rows="25"><?=$content;?></textarea>
<br>
<input type="submit" name="save_file" value="Save">
</form>

 

change.php

 

<?
ob_start();
$filename = $_POST[filename];
$theText = $_POST[theText];

$theText = stripslashes($theText);

$data = fopen($filename, "a");

fwrite($data,$theText);

fclose($data);

echo "File created or updated";
sleep(3);
header("Location: edit.php?page=$filename");
ob_end_flush();
?>

Link to comment
https://forums.phpfreaks.com/topic/52255-file-editor-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.