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