PHP/File Directory/file exists

Материал из Web эксперт
Перейти к: навигация, поиск

Checking for Existence with file_exists()

   <source lang="html4strict">

<? if ( file_exists ("data.txt") ) {

 print "The file exists!";

} ?>

 </source>
   
  


Checking the existence of a file

   <source lang="html4strict">

if (file_exists("/usr/local/htdocs/index.html")) {

   print "Index file is there.";

} else {

   print "No index file in /usr/local/htdocs.";

}

 </source>
   
  


Checking Whether a File Exists

   <source lang="html4strict">

<?

   if (file_exists("snapshot1.png")) {
           print "Snapshot1.png exists!\n";
   } else {
           print "Snapshot1.png does not exist!\n";
   }

?>

 </source>
   
  


file_exists() function returns true if it does, and false otherwise.

   <source lang="html4strict">

Its syntax is: bool file_exists (string file) <? $filename = "data.txt"; if (! file_exists ($filename)) :

    print "File $filename does not exist!";

endif; ?>

 </source>
   
  


The file_exists.php script checks to see whether the file is there

   <source lang="html4strict">

<?php $file_name="file_exists.php"; if(file_exists($file_name)) {

   echo ("$file_name does exist.");

} else {

   echo ("$file_name does not exist.");

} ?>

 </source>