RE: [PHP] delete file contents before writing?

From: Date: Tue, 04 Jun 2002 04:14:23 +0000
Subject: RE: [PHP] delete file contents before writing?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-100413@lists.php.net to get a copy of this message
If you really want to delete the file contents then open the file in write-only mode, like so: $open_file = fopen("$file_name","w"); -Naintara -----Original Message----- From: php-general-return-100409-naintara=del6.vsnl.net.in@lists.php.net [mailto:php-general-return-100409-naintara=del6.vsnl.net.in@lists.php.ne t]On Behalf Of Jas Sent: Monday, June 03, 2002 8:37 AM To: php-general@lists.php.net Subject: [PHP] delete file contents before writing? Not sure how I could do this as I could not find a functions on php.net to allow me to first delete the entire contents of a file "before" writting the changes supplied by a textarea. Here is what I have thus far: Page one - Form: <?php $file_name = 'blank.php'; $open_file = fopen("$file_name","rw"); if (!$open_file) { die("cannot open $file_name"); } else { $read_file = fread($open_file, filesize($file_name)); $strip_php = eregi_replace("<","&a&", $read_file); fclose($open_file); } ?> <form name="edit_passwords" method="post" action="edit_passwords.php"> <textarea name="passwords" cols="60" rows="7"><?php echo $strip_php; ?></textarea> <br> <input type="submit" name="save" value="save"> </form> Page two - open file and write changes: <?php if (!$passwords) { header ("Location: index.php"); } else { $file_name= "blank.php"; $file_open = fopen($file_name, "r+"); eregi_replace("&a&","<", $file_open); #eregi_replace("\","", $file_open); fwrite($file_open, $passwords); print ("$passwords was written to $file_name"); } ?> As of right now it opens the file and writes your changes, however it simply goes to the end of the file then begins writting. I would like to delete the contents of the file, then write the changes. Any help or pointers are appreciated! Jas -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php --- Incoming mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002 --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.363 / Virus Database: 201 - Release Date: 05/21/2002

« previous php.general (#100413) next »