$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->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.124

Twitter updates

  • New post: In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124— More
    11 January 2019
  • New ProcessWire main site rebuild ready for preview— More
    4 January 2019
  • Happy Holidays! This latest master version of ProcessWire contains hundreds of new additions, fixes, optimizations and more. This post covers all the highlights— More
    21 December 2018

Latest news

  • ProcessWire Weekly #245
    In the 245th issue of ProcessWire Weekly we're going to focus on some new documentation additions made just this week, cover a couple of new third party modules from Bernhard Baumrock, and introduce a magnificent new travel website called Uncover Colombia. Read on!
    Weekly.pw / 19 January 2019
  • ProcessWire 3.0.124 and new website launched
    In this week’s post, we’ll take a look a look at the new website and focus on some parts of it and how they were built. Then we’ll dive into the latest version of ProcessWire on the dev branch, version 3.0.124.
    Blog / 11 January 2019
  • Subscribe to weekly ProcessWire news

“Indeed, if ProcessWire can be considered as a CMS in its own right, it also offers all the advantages of a CMF (Content Management Framework). Unlike other solutions, the programmer is not forced to follow the proposed model and can integrate his/her ways of doing things.” —Guy Verville, Spiria Digital Inc.