waFiles

waFiles

Contents...

Methods

public static function convert ($file, $from, $to = 'UTF-8', $target = null)

Converts a text file to another charset.

Parameters

Returned value

Value of $target parameter specified for method call, or automatically generated path to converted file.

Example

$target_path = waFiles::convert($file_path, 'CP1251');

public static function copy ($source_path, $target_path, $skip_pattern = null)

Copies a file or directory contents.

Parameters

Example

//entire contents of 'wa-log' directory will copied to a directory named 'wa-log-temp', except for file and subdirectories whose names contain the word 'installer'
waFiles::copy('wa-log', 'wa-log-temp', '/installer/')

public static function create ($path, $is_dir = false)

Creates a directory or parent directory for a file.

Parameters

Example

//in spite of a period in the target name,
//which is usually used to separate the base file name from its extension,
//$id_dir = true explicitly tells that it is a directory, not a file
waFiles::create(wa()->getConfig()->getPath('cache').'/some.folder', true);

public static function delete ($path, $ignore_dir_errors = false)

Deletes a file or a directory. A directory containing subdirectories is deleted recursively.

Parameters

Example

waFiles::delete('wa-test')

public static function extension($file)

Returns file name extension.

Parameters

Example

waFiles::extension('robots.txt')

Result

txt

public static function formatSize ($file_size, $format = '%0.2f', $dimensions = 'Bytes,KBytes,MBytes,GBytes')

Returns formatted file size value.

Parameters

Example

waFiles::formatSize(1000000, '%0.2f', 'B,KB,MB,GB')

Result

0.95 MB

public static function getMimeType ($filename)

Determines the MIME type of a file by its name.

Parameters

Example

waFiles::getMimeType('index.php')

Result

text/html

public static function listdir ($dir, $recursive = false)

Returns the list of files and subdirectories in the specified directory.

Parameters

Example

waFiles::listdir('wa-config/apps')

Result

Array
(
    [0] => contacts
    [1] => shop
    [2] => site
    [3] => mailer
    [4] => helpdesk
    [5] => photos
    [6] => webasyst
    [7] => stickies
    [8] => checklists
    [9] => blog
)

Example

waFiles::listdir('wa-config/apps', true)

Result

Array
(
    [0] => contacts/person_fields_order.php
    [1] => contacts/config.php
    [2] => contacts/custom_fields.php
    [3] => site/domains/yourdomain.php
    [4] => mailer/plugins.php
    [5] => helpdesk/workflows.php
    [6] => helpdesk/graph.php
    [7] => photos/plugins.php
    [8] => photos/config.php
    [9] => blog/plugins.php
)

public static function move ($source_path, $target_path)

Moves a file or a directory to the specified parent directory.

Parameters

Example

$source = wa('myapp')->getAppPath('lib/config/data/.htaccess');
$target = wa('myapp')->getDataPath(null, true, 'images/.htaccess');
waFiles::move($source, $target);

public static function readFile ($file, $attach = null, $exit = true, $md5 = false)

Reads file contents and outputs it to the browser.

Parameters

Example

$path = wa('myapp')->getAppPath('lib/config/data/sample.zip');
waFiles::readFile($path);

public static function upload ($url, $path)

Uploads a file from the specified URL to a server directory.

Parameters

Example

$url = 'http://somedomain.com/archive.zip';
$path = wa()->getDataPath('files/pricelist.zip', true, 'myapp');
waFiles::upload($url, $path);

public static function write ($path, $content)

Writes data to a file.

Parameters

Example

$path = wa()->getDataPath('user/01.txt', false, 'myapp');
$content = 'some text';
waFiles::write($path, $content);