Properties

$error

$error

In case of the error, will contain error code.

$conf

$conf

$out

$out

Resource containing the reference to the file that we will write to.

Methods

__construct()

__construct(mixed  $conf = array()) : mixed

Parameters

mixed $conf

Returns

mixed —

__destruct()

__destruct() : mixed

Returns

mixed —

handleUpload()

handleUpload() : mixed

Returns

mixed —

getErrorCode()

getErrorCode() : int

Retrieve the error code

Returns

int —

Error code

getErrorMessage()

getErrorMessage() : string

Retrieve the error message

Returns

string —

Error message

combineChunksFor()

combineChunksFor(string  $file_name) : string

Combine chunks for specified file name.

Parameters

string $file_name

Throws

\Exception

In case of error generates exception with the corresponding code

Returns

string —

Path to the target file

getFileSizeFor()

getFileSizeFor(string  $file_name) : \number|false

Returns the size of the file in bytes for the given filename. Filename will be resolved against target_dir value defined in the config.

Parameters

string $file_name

Returns

\number|false —

getTargetPathFor()

getTargetPathFor(string  $file_name) : string

Resolves given filename against target_dir value defined in the config.

Parameters

string $file_name

Returns

string —

Resolved file path

sendNoCacheHeaders()

sendNoCacheHeaders() : mixed

Sends out headers that prevent caching of the output that is going to follow.

Returns

mixed —

sendCORSHeaders()

sendCORSHeaders(array  $headers = array(), mixed  $origin = '*') : mixed

Handles CORS.

Parameters

array $headers

Additional headers to send out

mixed $origin

Returns

mixed —

handleUpload()

handleUpload(array  $conf) : void

Parameters

array $conf

combineChunksFor()

combineChunksFor(string  $file_name) : string

Parameters

string $file_name

Returns

string —

getFileSizeFor()

getFileSizeFor(string  $file_name) : int

Parameters

string $file_name

Returns

int —

getTargetPathFor()

getTargetPathFor(string  $file_name) : string

Parameters

string $file_name

Returns

string —

sendNoCacheHeaders()

sendNoCacheHeaders() : void

sendCorsHeaders()

sendCorsHeaders() : void

getErrorCode()

getErrorCode() : int

Returns

int —

getErrorMessage()

getErrorMessage() : string

Returns

string —

handleChunk()

handleChunk(mixed  $chunk, mixed  $file_name) : mixed

Parameters

mixed $chunk
mixed $file_name

Returns

mixed —

handleFile()

handleFile(mixed  $file_name) : mixed

Parameters

mixed $file_name

Returns

mixed —

rename()

rename(mixed  $tmp_path, mixed  $file_path) : mixed

Parameters

mixed $tmp_path
mixed $file_path

Returns

mixed —

writeUploadTo()

writeUploadTo(string  $file_path, mixed  $file_data_name = false, mixed  $mode = 'wb') : string

Writes either a multipart/form-data message or a binary stream to the specified file.

Parameters

string $file_path

The path to write the file to

mixed $file_data_name
mixed $mode

Throws

\Exception

In case of error generates exception with the corresponding code

Returns

string —

Path to the target file

writeToFile()

writeToFile(array|string  $source_paths, string  $target_path, mixed  $mode = 'wb') : string

Write source or set of sources to the specified target. Depending on the mode sources will either overwrite the content in the target or will be appended to the target.

Parameters

array|string $source_paths
string $target_path
mixed $mode

Returns

string —

Path to the written target file

writeChunksToFile()

writeChunksToFile(string  $chunk_dir, string  $target_path) : string

Combine chunks from the specified folder into the single file.

Parameters

string $chunk_dir

Directory containing the chunks

string $target_path

The file to write the chunks to

Throws

\Exception

In case of error generates exception with the corresponding code

Returns

string —

File path containing combined chunks

isLastChunk()

isLastChunk(string  $file_name) : bool

Checks if currently processed chunk for the given filename is the last one.

Parameters

string $file_name

Returns

bool —

fileIsOK()

fileIsOK(mixed  $path) : bool

Runs cb_check_file filter on the file if defined in config.

Parameters

mixed $path

Returns

bool —

sanitizeFileName()

sanitizeFileName(string  $filename) : string

Sanitizes a filename replacing whitespace with dashes

Removes special characters that are illegal in filenames on certain operating systems and special characters requiring special escaping to manipulate at the command line. Replaces spaces and consecutive dashes with a single dash. Trim period, dash and underscore from beginning and end of filename.

Parameters

string $filename

The filename to be sanitized

Returns

string —

The sanitized filename

filesize()

filesize(string  $file) : int

PHPs filesize() fails to measure files larger than 2gb

Parameters

string $file

Path to the file to measure

Returns

int —

log()

log(string  $msg) : mixed

Log the message to the log_path, but only if debug is set to true.

Each message will get prepended with the current timestamp.

Parameters

string $msg

Returns

mixed —

cleanup()

cleanup() : mixed

Cleans up outdated *.part files and directories inside target_dir.

Files are considered outdated if they are older than max_file_age hours. (@see config options)

Returns

mixed —

rrmdir()

rrmdir(string  $dir) : mixed

Concise way to recursively remove a directory

Parameters

string $dir

Directory to remove

Returns

mixed —

lockTheFile()

lockTheFile(string  $file_name) : mixed

Obtain the blocking lock on the specified file. All processes looking to work with the same file will have to wait, until we release it (@see unlockTheFile).

Parameters

string $file_name

File to lock

Returns

mixed —

unlockTheFile()

unlockTheFile(string  $file_name) : mixed

Release the blocking lock on the specified file.

Parameters

string $file_name

File to lock

Returns

mixed —

reset()

reset() : mixed

Reset private variables to their initial values.

Returns

mixed —