FileUpload
in package
Used for managing backend processing of fields which have had data submitted via chunked file uploads, i.e. where chunked upload data has been stitched together by {@see FileUploadController}
Table of Contents
Methods
- checkFilename() : bool
- Check a given filename is allowed to be uploaded - blocks PHP files etc
- generateFromDisk() : string
- Generates a fake upload, including a session entry and a temp symlink, from an existing file on disk.
- getErrorMessage() : string
- Get a human friendly error string from the `$_FILES[*]['error]` value.
- getFile() : array<string|int, mixed>|null
- Get a single file object from the $_FILES superglobal with a query string.
- verify() : string
- Verify that the temporary file specified by the user exists and has valid content, and that the original file name is acceptable This is to be used during form processing upon a POST submission.
Methods
checkFilename()
Check a given filename is allowed to be uploaded - blocks PHP files etc
public
static checkFilename(string $filename) : bool
Parameters
- $filename : string
Return values
bool —True if allowed, false if not
generateFromDisk()
Generates a fake upload, including a session entry and a temp symlink, from an existing file on disk.
public
static generateFromDisk(string $filename, string $session_key, string $field_name) : string
This allows reuse of existing uploaded files on Form::chunkedUpload fields which support multiple files
Parameters
- $filename : string
-
The name of a file which exists in the files dir, e.g. 'image.jpg'
- $session_key : string
-
The session key used for file uploads, e.g. 'user-register' (see Fb::chunkedUpload)
- $field_name : string
-
The name of the field supplied to Fb::chunkedUpload, e.g. 'photos'
Tags
Return values
string —The filename of the newly generated symlink, which matches the naming format of files uploaded via the chunked uploader
getErrorMessage()
Get a human friendly error string from the `$_FILES[*]['error]` value.
public
static getErrorMessage(int $error) : string
Parameters
- $error : int
Return values
stringgetFile()
Get a single file object from the $_FILES superglobal with a query string.
public
static getFile(string $key) : array<string|int, mixed>|null
Parameters
- $key : string
-
like
multiedit_items.0.image
Return values
array<string|int, mixed>|null —null if the key doesn't exist, otherwise:
- name
- type
- tmp_name
- error
- size
verify()
Verify that the temporary file specified by the user exists and has valid content, and that the original file name is acceptable This is to be used during form processing upon a POST submission.
public
static verify(string $sess_key, string $field, int $index, array<string|int, mixed> $allowed_exts) : string
Parameters
- $sess_key : string
-
Session key related to the form, e.g. 'user-register'; see $params['sess_key'] of Fb::chunkedUpload
- $field : string
-
Name of field to process, e.g. 'image'
- $index : int
-
Array index; 0 for the first file, 1 for the next and so on
- $allowed_exts : array<string|int, mixed>
-
Array of string file-types that are allowed
Tags
Return values
string —Path to temporarily uploaded file; this can be used as the first argument to File::moveUpload to put the file in the desired permanent location.