$files API variable / WireFileTools class

Helpers for working with files and directories.

Click any linked item for full usage details and examples. Hookable methods are indicated with the icon. In addition to those shown below, the WireFileTools class also inherits all the methods and properties of: Wire.

Show $var?             Show args?        

Common

NameReturnSummary 
$files->chmod(string $path)
boolChange the read/write mode of a file or directory, consistent with ProcessWire's configuration settings 
$files->copy(string $src, string $dst)
boolCopy all files recursively from one directory ($src) to another directory ($dst) 
$files->filePutContents(string $filename, $contents)
int boolCreate (overwrite or append) a file, put the $contents in it, and adjust permissions 
$files->find(string $path)
arrayFind all files in the given $path recursively, and return a flat array of all found filenames 
$files->mkdir(string $path)
boolCreate a directory that is writable to ProcessWire and uses the defined $config chmod settings 
$files->rename(string $oldName, string $newName)
boolRename a file or directory and update permissions 
$files->rmdir(string $path)
boolRemove a directory and optionally everything within it (recursively) 
$files->send(string $filename)
(nothing)Send the contents of the given filename to the current http connection 
$files->unlink(string $filename)
boolUnlink/delete file with additional protections relative to PHP unlink() 

Advanced

NameReturnSummary 
$files->getNamespace(string $file)
stringGet the namespace used in the given .php or .module file 
$files->tempDir($name)
WireTempDirReturn a new temporary directory/path ready to use for files 

Includes

NameReturnSummary 
$files->include(string $filename)
boolInclude a PHP file passing it all API variables and optionally your own specified variables
$files->includeOnce(string $filename)
boolSame as include() method except that file will not be executed if it as previously been included 
$files->render(string $filename)
string boolGiven a filename, render it as a ProcessWire template file 

Filenames

NameReturnSummary 
$files->currentPath()
stringGet the current path / work directory 
$files->fileInPath(string $file, string $path)
boolIs given $file name in given $path name? (aka: is $file a subdirectory somewhere within $path) 
$files->unixDirName(string $dir)
stringConvert given directory name to use unix slashes and enforce trailing or no-trailing slash 
$files->unixFileName(string $file)
stringConvert given file name to use unix slashes (if it isn’t already) 

Additional methods and properties

In addition to the methods and properties above, WireFileTools also inherits the methods and properties of these classes:

API reference based on ProcessWire core version 3.0.137

Twitter updates

  • We added WebP image support this year and many have been adopting it in existing projects. We look at a process used for migrating existing websites to WebP images— from preliminary considerations to implementation & testing, w/lots of tips & tricks too: More
    16 August 2019
  • Core version 3.0.137 on the dev branch adds the ability to hook multiple methods at once, in a single call. This post details how it works and provides a useful example of how you might put it to use in your development environment— More
    2 August 2019
  • ProcessWire 3.0.136 updates our CKEditor version and adds a new backtrace() method to the core Debug class— More
    26 July 2019

Latest news

  • ProcessWire Weekly #275
    In the 275th issue of ProcessWire Weekly we're going to walk you through the new features included in ProcessWire 3.0.138, cover some WebP related stuff, and highlight recent forum posts and online resources. Read on!
    Weekly.pw / 17 August 2019
  • WebP images on an existing site
    In this post we’ll look at a process used for migrating an existing website to use WebP images. We’ll cover everything from preliminary considerations to implementation and testing, with lots of tips and tricks along the way.
    Blog / 16 August 2019
  • Subscribe to weekly ProcessWire news

I just love the easy and intuitive ProcessWire API. ProcessWire rocks!” —Jens Martsch, Web developer