$files

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?       Only hookable?    

Common

NameReturnSummary 
$files->size(string $path)
int string

Get size of file or directory (in bytes)

 

Manipulation

NameReturnSummary 
$files->chmod(string $path)
bool

Change the read/write mode of a file or directory, consistent with ProcessWire's configuration settings

 
$files->copy(string $src, string $dst)
bool

Copy all files recursively from one directory ($src) to another directory ($dst)

 
$files->filePutContents(string $filename, $contents)
int bool

Create (overwrite or append) a file, put the $contents in it, and adjust permissions

 
$files->mkdir(string $path)
bool

Create a directory that is writable to ProcessWire and uses the defined $config chmod settings

 
$files->rename(string $oldName, string $newName)
bool

Rename a file or directory and update permissions

 
$files->renameCopy(string $oldName, string $newName)
bool

Rename by first copying files to destination and then deleting source files

 
$files->rmdir(string $path)
bool

Remove a directory and optionally everything within it (recursively)

 
$files->unlink(string $filename)
bool

Unlink/delete file with additional protections relative to PHP unlink()

 

Advanced

NameReturnSummary 
$files->getNamespace(string $file)
string

Get the namespace used in the given .php or .module file

 
$files->tempDir()
WireTempDir

Return a new temporary directory/path ready to use for files

 

Http

NameReturnSummary 
$files->send($filename)
int

Send the contents of the given filename to the current http connection

 

Includes

NameReturnSummary 
$files->include(string $filename)
bool

Include a PHP file passing it all API variables and optionally your own specified variables

$files->includeOnce(string $filename)
bool

Same as include() method except that file will not be executed if it as previously been included

 
$files->render(string $filename)
string bool

Given a filename, render it as a ProcessWire template file

 

Filenames

NameReturnSummary 
$files->currentPath()
string

Get the current path / work directory

 
$files->fileInPath(string $file, string $path)
bool

Is given $file name in given $path name? (aka: is $file a subdirectory somewhere within $path)

 
$files->unixDirName(string $dir)
string

Convert given directory name to use unix slashes and enforce trailing or no-trailing slash

 
$files->unixFileName(string $file)
string

Convert 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.252