Jump to content

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

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.