Re: Loading Files & Writing...

From: Date: Sun, 04 Feb 2001 02:10:58 +0000
Subject: Re: Loading Files & Writing...
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-38046@lists.php.net to get a copy of this message
> I have a javascript to edit an html page thatI have written and have > been searching for a way to load a file into a text box and write the > contents to a file on the server when done in PHP. Is this possible? Any > direction is appreciated. Thanks in advance. <HTML><BODY><FORM METHOD=POST> <?php #Untested code: $path = "/full/path/to/file/php/can/write/to"; if (isset($submit)){ $file = fopen($path, 'w') or die("Unable to write to $path. Check permissions."); fwrite($file, $text, strlen($text)); fclose($file); } $file = fopen($path, 'r') or die("Unable to read from $path. Check permissions."); $text = fread($file, filesize($path)); ?> <TEXTAREA NAME=text COLS=60 ROWS=20><?php echo $text;?></TEXTAREA><BR> <INPUT TYPE=SUBMIT NAME=submit> </FORM></BODY></HTML> The tricky part is Security. You really don't want a file in the middle of your web-site that any random surfer can write to... Using the above code as-is would be pretty foolish under virtually all web sites.

« previous php.general (#38046) next »