Using file_exists, touch, and unlink together : unlink « File Directory « PHP






Using file_exists, touch, and unlink together

 
<?php
$file_name="test.txt";

if(file_exists($file_name)) {
    echo ("$file_name does exist.<br />");
}
else {
    echo ("The file $file_name does not exist.<br />");
    touch($file_name);
}
if(file_exists($file_name)) {
    echo ("The file $file_name does exist.<br />");
    unlink($file_name);
}
else {
    echo ("The file $file_name does not exist.<br />");
}
if(file_exists($file_name)) {
    echo ("The file $file_name does exist.<br />");
}
else {
    echo ("The file $file_name does not exist.<br />");
}
?>
  
  








Related examples in the same category

1.Deleting Files with unlink( )
2.Delete a file with the unlink() function.
3.Using the unlink() Function
4.You can remove an existing file with the unlink() function.
5.Deleting a file
6.Deleting files
7.Moving a file across filesystems