Learning PHP and MySQL

Example 11-22 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>");
 
}
?>

The output looks like Figure 11-18.

Posted by on 08/19 at 08:38 AM

Next entry: Example 11-23 Renaming a file

Previous entry: Example 11-21 Checking the permissions of a file

<< Back to main