Click to See Complete Forum and Search --> : Read and Write a file


scottyrob
04-14-2006, 06:09 AM
Hi, i am trying to create a script that echo's the source of a page into a textbox then i can edit it.. I will probably have to use things like fopen and fwite....

I have currently got this:

<link rel="stylesheet" href="main.css" type="text/css">

<?php

$pagename = $_GET["pagename"];

echo ("$pagename");

?>


Can someone tell me a step-by-step guide on what i need to do to make it so that i can echo the text into a textbox, edit it, click a submit button and update that page... I do not want someone to tell me the code but just a guide of what i need to do to achieve what i want...

I.E use fopen to open up a page, echo the text into a textbox, etc etc

Thanks very much!

scottyrob
04-14-2006, 06:13 AM
BTW, im not worried about security yet, ill work on that later.. i know if this gets into the wrong hands it could be a very dangerous script so i will figure that out later...

LiLcRaZyFuZzY
04-14-2006, 06:33 AM
You'll need the following functions:

file_get_contents() (http://php.net/filegetcontents)
fopen() (http://php.net/fopen)
fwrite() (http://php.net/fwrite)

password protect the page, even for testing

NogDog
04-14-2006, 06:49 AM
You might want to look at the readfile() function (http://www.php.net/readfile) as an easy, one-step method of reading and outputting a file, e.g.:

<?php
echo '<textarea name="text" cols="80" rows="20">';
readfile("the_source_code.html");
echo "</textarea>\n";
?>

Also, upon submission of the file, you'll need to use stripslashes() (http://www.php.net/stripslashes) before saving the text to the file if "magic quotes" are enabled (see get_magic_quotes_gpc() (http://www.php.net/get_magic_quotes_gpc)).