PHP/File Directory/file exists — различия между версиями

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

Версия 10:37, 26 мая 2010

Checking for Existence with file_exists()

 
<?
if ( file_exists ("data.txt") ) {
  print "The file exists!";
}
?>



Checking the existence of a file

 
if (file_exists("/usr/local/htdocs/index.html")) {
    print "Index file is there.";
} else {
    print "No index file in /usr/local/htdocs.";
}



Checking Whether a File Exists

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



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

 
Its syntax is: bool file_exists (string file)
<?
$filename = "data.txt";
if (! file_exists ($filename)) :
     print "File $filename does not exist!";
endif;
?>



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

 
<?php
$file_name="file_exists.php";
if(file_exists($file_name)) {
    echo ("$file_name does exist.");
}
else {
    echo ("$file_name does not exist.");
}
?>