$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 #518
    The 518th issue of ProcessWire Weekly brings in all the latest news from the ProcessWire community. Modules, sites, and more. Read on!
    Weekly.pw / 13 April 2024
  • ProFields Table Field with Actions support
    This week we have some updates for the ProFields table field (FieldtypeTable). These updates are primarily focused on adding new tools for the editor to facilitate input and management of content in a table field.
    Blog / 12 April 2024
  • Subscribe to weekly ProcessWire news

“We were really happy to build our new portfolio website on ProcessWire! We wanted something that gave us plenty of control on the back-end, without any bloat on the front end - just a nice, easy to access API for all our content that left us free to design and build however we liked.” —Castus, web design agency in Sheffield, UK