Skip to Main Content
PHP in a Nutshell
book

PHP in a Nutshell

by Paul Hudson
October 2005
Intermediate to advanced content levelIntermediate to advanced
372 pages
11h 35m
English
O'Reilly Media, Inc.
Content preview from PHP in a Nutshell

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";
    }

Warning

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.

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

PHP Cookbook

PHP Cookbook

Eric A. Mann
Programming PHP

Programming PHP

Rasmus Lerdorf, Kevin Tatroe
Learning PHP

Learning PHP

David Sklar

Publisher Resources

ISBN: 0596100671Errata Page