$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->size(string $path)
int stringGet size of file or directory (in bytes) 

Manipulation

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->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->renameCopy(string $oldName, string $newName)
boolRename by first copying files to destination and then deleting source files 
$files->rmdir(string $path)
boolRemove a directory and optionally everything within it (recursively) 
$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()
WireTempDirReturn a new temporary directory/path ready to use for files 

Http

NameReturnSummary 
$files->send($filename)
intSend the contents of the given filename to the current http connection 

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.236

Latest news

  • ProcessWire Weekly #549
    In the 549th issue of ProcessWire Weekly we’re going to check out the latest core updates, highlight one older yet still very relevant third party module, and more. Read on!
    Weekly.pw / 17 November 2024
  • Custom Fields Module
    This week we look at a new ProFields module named Custom Fields. This module provides a way to rapidly build out ProcessWire fields that contain any number of subfields/properties within them.
    Blog / 30 August 2024
  • 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