PHP - Working with Files and Directories

Getting Information on Files

PHP provides some functions that enable you to access useful file information.

For example, you can use file_exists()to discover whether a file exists before attempting to open it:

file_exists("/home/myFolder/myfile.txt" )

file_exists()returns true if the file at the specified path exists, or false otherwise.

You can use the filesize() function to determine the size of a file on the hard disk.

filesize("/home/myFolder/myfile.txt" )

This returns the size of the specified file in bytes, or false upon error.

Related Topics