The File class is a limited set of helper type methods.

Write File

This method’s signature is self explanatory. You supply the full path including filename as the first parameter. The data you want to write as the second parameter. The third parameter is the fopen mode. Fourth parameter is the file permissions for the file, and the fifth parameter is the directory permissions if the file does not already exist.

  $mode = 'wb' 
  $f_perm = 0644,
  $d_perm = 0755

Get File Info

Given a full path that includes a filename, returns basic file attributes. Returns FALSE if the file cannot be found.

  $single_attr = FALSE
Key Description
filename Name of file with extension
ext Extension w/o dot
realpath Full path (slashes all going same way)
path Path w/o filename (no trailing slash and slashes not necessarily going same way)
size Size in bytes
lastaccess The time the file was last accessed or used
lastmod The last modified time
perms File’s permissions as an array holding “numeric”, “octal”, and “full” elements
readable If file is readable
writable If file is writable

List Filenames

Reads the specified directory and builds an array containing the filenames. If second parameter is set to true, the returned array of filenames will include the full path instead of just the file’s name. The third parameter, which is false by default, allows you to retrieve all of the file names from any subdirectories.

  $include_path = FALSE, 
  $subdirs = FALSE

Is Writeable

Test for directory or file writability using SplFileInfo.

File::writable( $x );

Delete Directory

Deletes all files contained in the supplied directory path. If the second parameter is set to TRUE, any directories contained within the supplied base directory will also be deleted. If third parameter is TRUE, the emptied directory will be deleted.

  $subdirs = FALSE, 
  $remove_dir = FALSE

Reslash Path

Make all the slashes in a path go one way.

  $slash = '\\'