Jump to content

[SOLVED] File handling Questions!


pkirsch

Recommended Posts

If you open a file in write mode

 

<?php
$fp=fopen('empty.txt', 'w');
fclose($fp);                          // creates new empty file  (no fwrite required)
?>

 

it does not need to exist. If it doesn't exist the new file is create, if it does exist then the existing file is overwritten.

Oops, sorry I should have looked at the manual first.

 

You should do a check first though:

<?php
$filename = '/path/to/foo.txt';
$fp=fopen($filename, 'w');
if(file_exists($filename)){
     fclose($fp);                          // creates new empty file  (no fwrite required)
}else{
     echo 'Flie Doesn\'t Exist.';
}
?>

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.