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)

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

static int
convertIniSizeToBytes($val)

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 $source, string $target)

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

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(mixed $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

int
inival_to_bytes(string $val)

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

bool
isEmptyDirectory(string $dir)

No description

bool
is_image(string $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

array|mixed
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

send_file_old(string $file_path, bool|string $file_name = false, bool|string $file_mime = false)

Sends the passed file from the HDD to the user (supports even large files!) (Execution stops after this command!)

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

unzip(string $source, string $target)

Unzip and extract files from given source to target path.

Details

at line 21
__construct()

No description

at line 34
__destruct()

No description

at line 160
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 1224
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 493
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 836
bool check_for_virus(string $filename, bool $RemoveInfectedFile = false)

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

Return Value

bool

True if virus found

at line 802
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 1253
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 1200
static int convertIniSizeToBytes($val)

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

Parameters

$val

Return Value

int

at line 114
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 92
bool cp_r(string $source, string $target)

No description

Parameters

string $source

Directory

string $target

Target Directory

Return Value

bool

at line 1399
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 974
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 1284
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']

Return Value

array|string|false

at line 919
string du(string $path)

No description

Parameters

string $path

Directory

Return Value

string

Size in byte

at line 1531
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 943
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 1552
file_exists_cached($file)

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

Parameters

$file

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

No description

Parameters

$filelist
$extension_filter

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

No description

Parameters

$filelist
$wildcard
$match_full_path

at line 402
filter_onlyfiles($filelist)

No description

Parameters

$filelist

at line 1842
array getFileInfo(string $fsPath)

Get File Information

Parameters

string $fsPath

Return Value

array

at line 766
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 750
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 603
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 728
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 1482
array get_editable_file_types()

Editable File Types for XOI or directly via MS-Office

Return Value

array

at line 585
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 630
array get_file_contents(array|string $filelist)

No description

Parameters

array|string $filelist

Filelist

Return Value

array

at line 508
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 565
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 460
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 477
string|bool get_file_extension_by_mime(string $mime)

No description

Parameters

string $mime

type

Return Value

string|bool

at line 445
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 1089
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 1003
string get_friendly_filename(string $file)

No description

Parameters

string $file

Original Filename

Return Value

string

at line 1023
get_friendly_filesize(mixed $file)

Get friendly filesize

Parameters

mixed $file

at line 1180
int get_max_upload_size()

No description

Return Value

int

Max. Upload Size in Bytes

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

No description

Parameters

string $file

Filename

Return Value

bool|mixed

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

No description

Parameters

string $extension

Extension

Return Value

bool|mixed

at line 1033
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 711
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 686
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 672
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 28
init()

No description

at line 1191
int inival_to_bytes(string $val)

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

Parameters

string $val

Return Value

int

at line 877
bool isEmptyDirectory(string $dir)

No description

Parameters

string $dir

Return Value

bool

Exceptions

UnexpectedValueException

at line 908
bool is_image(string $filepath)

No description

Parameters

string $filepath

absolute filepath

Return Value

bool

True if is image

at line 1072
is_ioncube_encoded($filename)

Checks if the passed PHP file is encoded via Ioncube

Parameters

$filename

at line 1063
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 860
bool is_subfolder($subfolder, $parent)

No description

Parameters

$subfolder
$parent

Return Value

bool

at line 252
array|mixed 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|mixed

at line 317
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 54
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 79
bool mkdir_r($dirname, int $mode = 0777)

No description

Parameters

$dirname
int $mode

Return Value

bool

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

No description

Parameters

string $source

pathToFile

string $target

pathToFile

Return Value

bool

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

No description

Parameters

string $file

Filename

mixed $content

content

Return Value

int

at line 890
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 932
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 1120
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 287
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 124
rm(string $filename)

No description

Parameters

string $filename

File to be deleted

at line 144
mixed rmdir(string $dirname)

No description

Parameters

string $dirname

Directory

Return Value

mixed

Returns TRUE on success or FALSE on failure

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

No description

Parameters

string $dirname

Directory

Return Value

array|bool

at line 1574
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 1413
send_file_old(string $file_path, bool|string $file_name = false, bool|string $file_mime = false)

Sends the passed file from the HDD to the user (supports even large files!) (Execution stops after this command!)

Parameters

string $file_path

Filepath on HDD

bool|string $file_name

Filename which should be send to the user

bool|string $file_mime

Mime type to send

at line 1812
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 1778
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 1764
unzip(string $source, string $target)

Unzip and extract files from given source to target path.

Parameters

string $source
string $target