class File

Properties

$trash_folder
array $curl_info

Contains the info returned by CURL when calling $this->download_file_from_url();

Methods

__construct()

No description

__destruct()

No description

bool
backup_to_trash($file_or_folder, $force = false)

Copies the passed file/folder to the trash folder

string
basename(string $string)

UTF8 Compatible basename(), because php::basename() is still buggy (e.g.: removes all umlauts at the beginning of a filename)

string
change_file_extension(string $filename, string $new_ext)

No description

bool
check_for_virus(string $filename, bool $RemoveInfectedFile = false, string $summary = null)

Check a file for virus If a virus is found TRUE is returned, otherwise FALSE To use this function ClamAV (Daemon) had to be installed and the user belonged to the webserver group

void
check_uploaded_file(string $tempName, string $name)

Checks files uploaded through forms for:

string
complete_absolute_url(string $url)

Complete an URL to be absolute

string
concatPaths($paths = [])

Builds a path by concating multiple path elements It ensures all path elements use the proper separator when being glued and secures all elements to avoid relative escapes (../ is not allowed) to ensure e.g. frontend input can not escape folder

static float|int
convertIniSizeToBytes(string $sizeExpression)

Converts a PHP INI Size as memory_limit size string to a byte value

bool
cp(string $file, string $target)

No description

bool
cp_r(string $sourceDir, string $targetDir, bool $onlyContents = false)

No description

int
curl_header_cb(mixed $ch, mixed $header)

callback function for getting header values from curl, used by download_file_from_url

string
decode_file(string $filename, string $password, bool $copy_to_tmp = false)

No description

array|string|false
download_file_from_url(string $url, bool $return_data = false)

Downloads a file from a url.

string
du(string $path)

No description

bool
enable_stream_wrapper(string $wrapper)

Include / Enable a certain stream wrapper Example: "smb://user:pass@server/share/path"

string
encode_file(string $filename, string $password, bool $copy_to_tmp = false)

No description

file_exists_cached($file)

Checks if the passed file exists, cached for the current call

filter_by_extension($filelist, $extension_filter = false)

No description

filter_by_wildcard($filelist, $wildcard, $match_full_path = false)

No description

filter_onlyfiles($filelist)

No description

array
getFileInfo(string $fsPath)

Get File Information

array
getVideoExtensions()

returns an array with ffmpeg compatible video extensions this is populated from video worker

string
get_cache_file(string $prefix, string $filename, array|bool $partition_index = false)

No description

get_cascaded_folder(int $id)

Returns a cascaded path based on the passed id to prevent file system storage limitations. 10.000 files per folder will be used.

bool|mixed|string
get_contents(string $target, int $request_timeout = 20, int $connection_timeout = 5)

Returns the content of a file or url by curl.

bool|string
get_document_temp_folder($instance, $document_id, int $post_type = 0, bool $return_alternative_temp_folder = true)

No description

array
get_editable_file_types()

Editable File Types for XOI or directly via MS-Office

mixed|null
get_file_charset(string|bool $file_path)

Returns the charset of the given file. This method uses exec() to

array
get_file_contents(array|string $filelist)

No description

array|false
get_file_details(string|string[] $filelist, bool $details = false)

No description

null|string
get_file_encoding(string $file_path)

Returns the encoding of the file.

string
get_file_extension(string $filename)

No description

string|bool
get_file_extension_by_mime(string $mime)

No description

string
get_filename_without_extension(string $filename)

No description

string
get_first_file_found(array $files, bool|string $path = false)

No description

string
get_friendly_filename(string $file)

No description

get_friendly_filesize(string $file)

Get friendly filesize

int
get_max_upload_size()

No description

bool|mixed
get_mime(string $file)

No description

bool|mixed
get_mime_by_extension(string $extension)

No description

string
get_secure_filename(string $filename, bool $strict = true)

No description

string
get_temp_backup_folder()

Creates a temporary folder for backup data and returns the path.

string
get_temp_folder(bool $delete_on_destruction = false)

No description

string
get_temp_name(bool $delete_on_destruction = false)

No description

init()

No description

float|int
inival_to_bytes(string $val) deprecated

function used by get_max_upload_size to convert the ini values to a byte values

bool
isEmptyDirectory(string $dir)

No description

bool
isImageExtension(string $ext)

If file extension considered an image format?

bool
isVideoExtension(string $ext)

If file extension considered a rocessable and previewable video format? Must be compatible and supported by ffmpeg conversion process

bool
is_image($filepath)

No description

is_ioncube_encoded($filename)

Checks if the passed PHP file is encoded via Ioncube

bool
is_secure_filename(string $filename)

Check if Filename meets the nonstrict security guidelines

bool
is_subfolder($subfolder, $parent)

No description

bool
is_video(string $filepath)

No description

array|false
ll(string $dirname, array|bool $extension_filter = false, bool $skip_directories = true)

No description

array
ll_r(string $dir, array|bool $extension_filter = false, bool $return_folders = false, bool $limit = null)

Returns an array with all files in the given directory (Recursive)

bool
mkdir(int $pathname, int $mode = 0777, bool $recursive = false)

No description

bool
mkdir_r($dirname, int $mode = 0777)

No description

bool
mv(string $source, string $target)

No description

int
put_file_contents(string $file, mixed $content)

No description

string
relativize_path(string $subfolder, $parent)

No description

bool
rename(string $current_name, string $new_name)

No description

string
replace_vars_in_file(mixed $filename, mixed $vars = array(), int $ext = 'auto', mixed $send_file = false)

Replaces the passed vars in the given file The file must contain markers in the format {{VARNAME}} The engine currently supports DOCX and TXT formats for replacement

array
rglob(string $path, int $flags = 0, int $stop_after = null)

Returns all files for given path recursive. It is allowed to use glob pattern to restrict the result.

rm(string $filename)

No description

mixed
rmdir(string $dirname)

No description

array|bool
rmdir_r(string $dirname)

No description

bool|mixed|string
send_file($path_to_file, false $filename = false, false $download_params = false)

Send file to client/browser

setPermissionsSystem(string $path)

Set permissions for files writable system user only Should be applied to files in class, modules, etc -> readable for web and writable to system only \XF_SYSTEM_UID and \XF_WEBSERVER_UID

setPermissionsWeb(string $path)

Set permissions for files writable to the web user and system user Should be applied to files in _log, _files, etc -> readable and writable to system AND web \XF_SYSTEM_UID and \XF_WEBSERVER_UID

string|null
tail(string $filepath, int $lines = 1, bool $adaptiveBuffer = true)

Slightly modified version of http://www.geekality.net/2011/05/28/php-tail-tackling-large-files/

unzip(string $source, string $target)

Unzip and extract files from given source to target path.

?string
zip(array $filesToZip, string|null $zipFileDestination = null)

Zip all files to

Details

at line 22
__construct()

No description

at line 35
__destruct()

No description

at line 164
bool backup_to_trash($file_or_folder, $force = false)

Copies the passed file/folder to the trash folder

Parameters

$file_or_folder
$force

Return Value

bool

Returns true if copy has been successfull (requires use_trash to be enabled if not forced)

at line 1326
string basename(string $string)

UTF8 Compatible basename(), because php::basename() is still buggy (e.g.: removes all umlauts at the beginning of a filename)

Parameters

string $string

Return Value

string

at line 500
string change_file_extension(string $filename, string $new_ext)

No description

Parameters

string $filename Filename
string $new_ext

New Extension (e.g. 'tar')

Return Value

string

Filename with changed extension

at line 845
bool check_for_virus(string $filename, bool $RemoveInfectedFile = false, string $summary = null)

Check a file for virus If a virus is found TRUE is returned, otherwise FALSE To use this function ClamAV (Daemon) had to be installed and the user belonged to the webserver group

Parameters

string $filename

Absolute disk file path

bool $RemoveInfectedFile

Delete the file, if it contains a virus

string $summary

Return Value

bool

True if virus found

at line 810
void check_uploaded_file(string $tempName, string $name)

Checks files uploaded through forms for:

  • antivirus (if endbaled) and removes infected files
    • file extension whitelist (if set)

Logging and user interaction is the calling functions responsibility

  • example catch exception and output/log message

Parameters

string $tempName

full path and filename on the systen like in $_FILES['upload']['tmp_name']

string $name

original filename like in $_FILES['upload']['name']

Return Value

void

Exceptions

ComplianceException

at line 1354
string complete_absolute_url(string $url)

Complete an URL to be absolute

Parameters

string $url

Return Value

string

Completed URL starting with http/https

at line 891
string concatPaths($paths = [])

Builds a path by concating multiple path elements It ensures all path elements use the proper separator when being glued and secures all elements to avoid relative escapes (../ is not allowed) to ensure e.g. frontend input can not escape folder

Parameters

$paths

array Path Elements

Return Value

string

at line 1296
static float|int convertIniSizeToBytes(string $sizeExpression)

Converts a PHP INI Size as memory_limit size string to a byte value

Parameters

string $sizeExpression

Return Value

float|int

at line 118
bool cp(string $file, string $target)

No description

Parameters

string $file

Source File

string $target

Target File

Return Value

bool

was Action successful?

at line 93
bool cp_r(string $sourceDir, string $targetDir, bool $onlyContents = false)

No description

Parameters

string $sourceDir Directory
string $targetDir

Target Directory

bool $onlyContents

Does not copy folder, only contents of the sourceDir

Return Value

bool

at line 1505
int curl_header_cb(mixed $ch, mixed $header)

callback function for getting header values from curl, used by download_file_from_url

Parameters

mixed $ch
mixed $header

Return Value

int

at line 1068
string decode_file(string $filename, string $password, bool $copy_to_tmp = false)

No description

Parameters

string $filename filename
string $password password
bool $copy_to_tmp

copy to tempfolder before encryption

Return Value

string

decoded filename or false

at line 1386
array|string|false download_file_from_url(string $url, bool $return_data = false)

Downloads a file from a url.

If the URL is placed on the current host it will be requested using the current user session Note: Please make sure to set the PHP timeout if you expect to download large files. The download is aborted if it takes longer than 5 minutes.

Parameters

string $url
bool $return_data

If set to true, the function will return an array containing the binary and all header infos: $a['binary'], $a['filename'], $a['header'] otherwise path to a tmpfile

Return Value

array|string|false

at line 1013
string du(string $path)

No description

Parameters

string $path Directory

Return Value

string

Size in byte

at line 1660
bool enable_stream_wrapper(string $wrapper)

Include / Enable a certain stream wrapper Example: "smb://user:pass@server/share/path"

Parameters

string $wrapper

(smb, dropbox)

Return Value

bool

at line 1037
string encode_file(string $filename, string $password, bool $copy_to_tmp = false)

No description

Parameters

string $filename filename
string $password password
bool $copy_to_tmp

copy to tempfolder before encryption

Return Value

string

encoded filename or false

at line 1681
file_exists_cached($file)

Checks if the passed file exists, cached for the current call

Parameters

$file

at line 352
filter_by_extension($filelist, $extension_filter = false)

No description

Parameters

$filelist
$extension_filter

at line 386
filter_by_wildcard($filelist, $wildcard, $match_full_path = false)

No description

Parameters

$filelist
$wildcard
$match_full_path

at line 409
filter_onlyfiles($filelist)

No description

Parameters

$filelist

at line 1991
array getFileInfo(string $fsPath)

Get File Information

Parameters

string $fsPath

Return Value

array

at line 982
array getVideoExtensions()

returns an array with ffmpeg compatible video extensions this is populated from video worker

Return Value

array

at line 774
string get_cache_file(string $prefix, string $filename, array|bool $partition_index = false)

No description

Parameters

string $prefix

Prefix for your cache storage. Should be unique across the system, e.g. xm_dms_thumbs

string $filename

Filename of the file. You need to determine the possible filename by yourself

array|bool $partition_index

If you want to specify the partitioning schema manually pass the indexes as array, e.g. array('a', 'b') ==> Path: .../a/b/...

Return Value

string

Returns complete folder + filename

at line 758
get_cascaded_folder(int $id)

Returns a cascaded path based on the passed id to prevent file system storage limitations. 10.000 files per folder will be used.

e.g. IDs 1-9999 will be in folder k0/[1-9999]/ and 10000 to 19999 will be in folder k1/[10000-19999]/

Parameters

int $id

at line 610
bool|mixed|string get_contents(string $target, int $request_timeout = 20, int $connection_timeout = 5)

Returns the content of a file or url by curl.

Parameters

string $target
int $request_timeout
int $connection_timeout

Return Value

bool|mixed|string

at line 736
bool|string get_document_temp_folder($instance, $document_id, int $post_type = 0, bool $return_alternative_temp_folder = true)

No description

Parameters

$instance
$document_id
int $post_type
bool $return_alternative_temp_folder

Return Value

bool|string

at line 1611
array get_editable_file_types()

Editable File Types for XOI or directly via MS-Office

Return Value

array

at line 592
mixed|null get_file_charset(string|bool $file_path)

Returns the charset of the given file. This method uses exec() to

Parameters

string|bool $file_path

Charset of the file or null.

Return Value

mixed|null

at line 637
array get_file_contents(array|string $filelist)

No description

Parameters

array|string $filelist Filelist

Return Value

array

at line 515
array|false get_file_details(string|string[] $filelist, bool $details = false)

No description

Parameters

string|string[] $filelist

Pass path to single file or array of paths

bool $details

Set true if you want more details for supported files (e.g. via pdfinfo)

Return Value

array|false

at line 572
null|string get_file_encoding(string $file_path)

Returns the encoding of the file.

Parameters

string $file_path

iso | utf-8

Return Value

null|string

at line 467
string get_file_extension(string $filename)

No description

proper handling of files beginning with '.', e.g. ".Thumbs.db" would have correctly the extension '.db' and not '.Thumbs.db'

Parameters

string $filename Filename

Return Value

string

at line 484
string|bool get_file_extension_by_mime(string $mime)

No description

Parameters

string $mime type

Return Value

string|bool

at line 452
string get_filename_without_extension(string $filename)

No description

proper handling of files beginning with '.', e.g. ".Thumbs.db" would have correctly the filename '.Thumbs' and not an empty string

Parameters

string $filename Filename

Return Value

string

at line 1182
string get_first_file_found(array $files, bool|string $path = false)

No description

Parameters

array $files files
bool|string $path path

Return Value

string

found file as given in array or false

at line 1097
string get_friendly_filename(string $file)

No description

Parameters

string $file

Original Filename

Return Value

string

at line 1116
get_friendly_filesize(string $file)

Get friendly filesize

Parameters

string $file path

at line 1273
int get_max_upload_size()

No description

Return Value

int

Max. Upload Size in Bytes

at line 439
bool|mixed get_mime(string $file)

No description

Parameters

string $file Filename

Return Value

bool|mixed

at line 424
bool|mixed get_mime_by_extension(string $extension)

No description

Parameters

string $extension Extension

Return Value

bool|mixed

at line 1126
string get_secure_filename(string $filename, bool $strict = true)

No description

Parameters

string $filename

Input Filename

bool $strict

Strict (Strict means only A-z_.-)

Return Value

string

Output Filename

at line 719
string get_temp_backup_folder()

Creates a temporary folder for backup data and returns the path.

Return Value

string

Path toi temporary folder.

at line 694
string get_temp_folder(bool $delete_on_destruction = false)

No description

Parameters

bool $delete_on_destruction

If true this temporary file gets removed immediately after this page call is finished

Return Value

string

at line 680
string get_temp_name(bool $delete_on_destruction = false)

No description

Parameters

bool $delete_on_destruction

If true this temporary file gets removed immediately after this page call is finished

Return Value

string

at line 29
init()

No description

at line 1285
float|int inival_to_bytes(string $val) deprecated

deprecated use File::convertIniSizeToBytes()

function used by get_max_upload_size to convert the ini values to a byte values

Parameters

string $val

Return Value

float|int

at line 909
bool isEmptyDirectory(string $dir)

No description

Parameters

string $dir

Return Value

bool

Exceptions

UnexpectedValueException

at line 947
bool isImageExtension(string $ext)

If file extension considered an image format?

Parameters

string $ext

File Extension e.g. jpg, gif

Return Value

bool

True if is image

at line 973
bool isVideoExtension(string $ext)

If file extension considered a rocessable and previewable video format? Must be compatible and supported by ffmpeg conversion process

Parameters

string $ext

File Extension e.g. mp4, ogg

Return Value

bool

True if is video

at line 935
bool is_image($filepath)

No description

Parameters

$filepath

Return Value

bool

at line 1165
is_ioncube_encoded($filename)

Checks if the passed PHP file is encoded via Ioncube

Parameters

$filename

at line 1156
bool is_secure_filename(string $filename)

Check if Filename meets the nonstrict security guidelines

Parameters

string $filename

Return Value

bool

true if secure

at line 874
bool is_subfolder($subfolder, $parent)

No description

Parameters

$subfolder
$parent

Return Value

bool

at line 959
bool is_video(string $filepath)

No description

Parameters

string $filepath

absolute filepath

Return Value

bool

True if is image

at line 256
array|false ll(string $dirname, array|bool $extension_filter = false, bool $skip_directories = true)

No description

Parameters

string $dirname Directory
array|bool $extension_filter

Array with valid extensions

bool $skip_directories

Set false to receive also directories (./..)

Return Value

array|false

at line 321
array ll_r(string $dir, array|bool $extension_filter = false, bool $return_folders = false, bool $limit = null)

Returns an array with all files in the given directory (Recursive)

Parameters

string $dir Directory
array|bool $extension_filter

with valid extensions

bool $return_folders Folders?
bool $limit

Return Value

array

at line 55
bool mkdir(int $pathname, int $mode = 0777, bool $recursive = false)

No description

Parameters

int $pathname

Directory rights (Default: 0775)

int $mode

The mode is 0777 by default, which means the widest possible access. For more information on modes, read the details on the chmod() page.

bool $recursive

Allows the creation of nested directories specified in the pathname.

Return Value

bool

at line 80
bool mkdir_r($dirname, int $mode = 0777)

No description

Parameters

$dirname
int $mode

Return Value

bool

at line 669
bool mv(string $source, string $target)

No description

Parameters

string $source pathToFile
string $target pathToFile

Return Value

bool

at line 657
int put_file_contents(string $file, mixed $content)

No description

Parameters

string $file Filename
mixed $content content

Return Value

int

at line 922
string relativize_path(string $subfolder, $parent)

internal  param string $parentParent Folder, e.g. /server/dev/
 

No description

Parameters

string $subfolder

Child Folder, e.g. /server/dev/dw.dev/

$parent

Return Value

string

Returns the relativized path

at line 1026
bool rename(string $current_name, string $new_name)

No description

Parameters

string $current_name

current name

string $new_name

new name

Return Value

bool success

at line 1213
string replace_vars_in_file(mixed $filename, mixed $vars = array(), int $ext = 'auto', mixed $send_file = false)

Replaces the passed vars in the given file The file must contain markers in the format {{VARNAME}} The engine currently supports DOCX and TXT formats for replacement

Parameters

mixed $filename $filename
mixed $vars
int $ext
mixed $send_file

Set to true if file shall not be directly send to user but be returned as binary data

Return Value

string

at line 291
array rglob(string $path, int $flags = 0, int $stop_after = null)

Returns all files for given path recursive. It is allowed to use glob pattern to restrict the result.

E.g. /server/xelos/modules/*.yml return all YAML files.

Parameters

string $path

The path where to look up (pattern are allowed (*,?)

int $flags

One of the GLOB_ constants

int $stop_after

Number at which file count induce the break.

Return Value

array

An array with all files or directories.

at line 128
rm(string $filename)

No description

Parameters

string $filename

File to be deleted

at line 148
mixed rmdir(string $dirname)

No description

Parameters

string $dirname Directory

Return Value

mixed

Returns TRUE on success or FALSE on failure

at line 212
array|bool rmdir_r(string $dirname)

No description

Parameters

string $dirname Directory

Return Value

array|bool

at line 1703
bool|mixed|string send_file($path_to_file, false $filename = false, false $download_params = false)

Send file to client/browser

Parameters

$path_to_file
false $filename
false $download_params

Return Value

bool|mixed|string

Exceptions

Exception

at line 1961
setPermissionsSystem(string $path)

Set permissions for files writable system user only Should be applied to files in class, modules, etc -> readable for web and writable to system only \XF_SYSTEM_UID and \XF_WEBSERVER_UID

Parameters

string $path

at line 1927
setPermissionsWeb(string $path)

Set permissions for files writable to the web user and system user Should be applied to files in _log, _files, etc -> readable and writable to system AND web \XF_SYSTEM_UID and \XF_WEBSERVER_UID

Parameters

string $path

at line 1523
string|null tail(string $filepath, int $lines = 1, bool $adaptiveBuffer = true)

Parameters

string $filepath
int $lines
bool $adaptiveBuffer

Return Value

string|null

at line 1913
unzip(string $source, string $target)

Unzip and extract files from given source to target path.

Parameters

string $source
string $target

at line 1890
?string zip(array $filesToZip, string|null $zipFileDestination = null)

Zip all files to

Parameters

array $filesToZip

Preferred as ['folder/entryNameInZip.jpg','/path/to/original-file.jpg']

string|null $zipFileDestination

Return Value

?string

Path to zip file on success, null on failure