Section 13.5. Checking Whether a File Exists


13.5. Checking Whether a File Exists

The act of checking whether a file exists is one of the most basic file-related tasks you'll want to do, and file_exists( ) makes it as easy as it should be. Specify the filename to check as the only parameter, and it returns true if the file exists and false otherwise. For example:

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

The result of file_exists( ) is cached, which means you first need to call the clearstatcache( ) function if you want to be absolutely sure a file exists.




PHP in a Nutshell
Ubuntu Unleashed
ISBN: 596100671
EAN: 2147483647
Year: 2003
Pages: 249

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net