$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

  • ProcessWire 3.0.142 has a lot of updates but the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look at that, and also outline all of the new features in the just-released FormBuilder v40— More
    11 October 2019
  • This week’s dev branch version brings you improvements to ProcessWire’s input->cookie API variable, plus it adds the ability to modify system URLs and paths at runtime. This post also includes some examples to demonstrate just how useful this can be— More
    20 September 2019
  • New post: This week we’ll take a look at a new version of FormBuilder that's on the way (with a screencast), as well as the latest version of the core: ProcessWire 3.0.140— More
    6 September 2019

Latest news

  • ProcessWire Weekly #283
    The 283rd issue of ProcessWire Weekly introduces ProcessWire 3.0.142 and FormBuilder v40, highlights some conference content, and features a new weekly poll continuing with the #processwireworks theme. Read on!
    Weekly.pw / 12 October 2019
  • ProcessWire 3.0.142 core updates
    This latest version of the core on the dev branch has a lot of updates, bnd the biggest is the addition of custom fields support for file and image fields. In this post, we take a closer look and also outline all of the new features in the just-released FormBuilder v40.
    Blog / 11 October 2019
  • Subscribe to weekly ProcessWire news

“To Drupal, or to ProcessWire? The million dollar choice. We decided to make an early switch to PW. And in retrospect, ProcessWire was probably the best decision we made. Thanks are due to ProcessWire and the amazing system and set of modules that are in place.” —Unni Krishnan, Founder of PigtailPundits