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.
Common
Name | Return | Summary | |
---|---|---|---|
$files->size() $files->size(string $path) $files->size(string $path, $options = []) | int string | Get size of file or directory (in bytes) |
Retrieval
Name | Return | Summary | |
---|---|---|---|
$files->exists() $files->exists(string $filename) $files->exists(string $filename, $options = '') | bool | Does the given file/link/dir exist? | |
$files->fileGetContents() $files->fileGetContents(string $filename) $files->fileGetContents(string $filename, int $offset = 0, int $maxlen = 0) | bool string | Get contents of file | |
$files->find() $files->find(string $path) $files->find(string $path, array $options = []) | array | Find all files in the given $path recursively, and return a flat array of all found filenames |
Manipulation
Advanced
Name | Return | Summary | |
---|---|---|---|
$files->getNamespace() $files->getNamespace(string $file) $files->getNamespace(string $file, bool $fileIsContents = false) | string | Get the namespace used in the given .php or .module file | |
$files->tempDir() $files->tempDir() $files->tempDir($name = '', $options = []) | WireTempDir | Return a new temporary directory/path ready to use for files |
Archives
Name | Return | Summary | |
---|---|---|---|
$files->unzip() $files->unzip(string $file, string $dst) $files->unzip(string $file, string $dst) | array | Unzips the given ZIP file to the destination directory | |
$files->zip() $files->zip(string $zipfile, $files) $files->zip(string $zipfile, $files, array $options = []) | array | Creates a ZIP file |
Http
Name | Return | Summary | |
---|---|---|---|
$files->send() $files->send($filename) $files->send($filename, array $options = [], array $headers = []) | int | Send the contents of the given filename to the current http connection |
CSV
Name | Return | Summary | |
---|---|---|---|
$files->getAllCSV() $files->getAllCSV(string $filename) $files->getAllCSV(string $filename, array $options = []) | array | Get all rows from a CSV file | |
$files->getCSV() $files->getCSV(string $filename) $files->getCSV(string $filename, array $options = []) | array false | Get next row from a CSV file |
Includes
Name | Return | Summary | |
---|---|---|---|
$files->include() $files->include(string $filename) $files->include(string $filename, array $vars = [], array $options = []) | bool | Include a PHP file passing it all API variables and optionally your own specified variables | |
$files->includeOnce() $files->includeOnce(string $filename) $files->includeOnce(string $filename, array $vars = [], array $options = []) | bool | Same as include() method except that file will not be executed if it as previously been included | |
$files->render() $files->render(string $filename) $files->render(string $filename, array $vars = [], array $options = []) | string bool | Given a filename, render it as a ProcessWire template file |
Filenames
Name | Return | Summary | |
---|---|---|---|
$files->currentPath() $files->currentPath() $files->currentPath() | string | Get the current path / work directory | |
$files->fileInPath() $files->fileInPath(string $file, string $path) $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() $files->unixDirName(string $dir) $files->unixDirName(string $dir, bool $trailingSlash = true) | string | Convert given directory name to use unix slashes and enforce trailing or no-trailing slash | |
$files->unixFileName() $files->unixFileName(string $file) $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.236