Upload
in package
Class that handles file uploads and checking types
Table of Contents
- $extension : string
- $fileId : int
- $filePath : string
- $mime : string
- $ref : string
- $size : int
- $srcName : string
- $res : Request
- audio() : int
- Uploads a file, which must be an audio file (mp3, wav, wma, ogg, m4a, aiff or aac)
- image() : int
- Uploads a file, which must be an image (jpg, jpeg, png or bmp)
- upload() : int
- Uploads a file to an upload folder
- video() : int
- Uploads a file, which must be a video (mp4, m4a, m4v, mov, 3gp, ogg, webm, flv, mkv, avi or wmv)
Properties
$extension
public
string
$extension
File extension of the uploading file
$fileId
public
int
$fileId
File Id, set after upload
$filePath
public
string
$filePath
Path to the uploading file
$mime
public
string
$mime
MIME-Type
$ref
public
string
$ref
Reference
$size
public
int
$size
Size of the uploading file in bytes
$srcName
public
string
$srcName
Source name of the uploading file
$res
private
Request
$res
Request object of the current request
Methods
audio()
Uploads a file, which must be an audio file (mp3, wav, wma, ogg, m4a, aiff or aac)
public
audio(array<string|int, mixed> $file, string $uploadDir[, int $maxSize = FILE_SIZE_10MB ]) : int
An implementation of the upload method with an audio filter. This function will handle file uploads for you and make sure the type and the size are as defined. It also handles the movement to an upload folder. Be sure to change upload_max_filesize and post_max_size in you php.ini
Parameters
- $file : array<string|int, mixed>
-
The $_FILES entry of the file. Example getFile("voice_rec")
- $uploadDir : string
-
The path to which the file will be uploaded
- $maxSize : int = FILE_SIZE_10MB
-
The maximum size of the file in bytes (0 = no limit). Use the defined constants like FILE_SIZE_10MB
Return values
int —The result of the upload. This could be something like UPLOAD_SUCCESS or UPLOAD_ERROR_TOO_BIG
image()
Uploads a file, which must be an image (jpg, jpeg, png or bmp)
public
image(array<string|int, mixed> $file, string $uploadDir[, int $maxSize = FILE_SIZE_2MB ]) : int
An implementation of the upload method with an image filter. This function will handle file uploads for you and make sure the type and the size are as defined. It also handles the movement to an upload folder. Be sure to change upload_max_filesize and post_max_size in you php.ini
Parameters
- $file : array<string|int, mixed>
-
The $_FILES entry of the file. Example getFile("profile_picture")
- $uploadDir : string
-
The path to which the file will be uploaded
- $maxSize : int = FILE_SIZE_2MB
-
The maximum size of the file in bytes (0 = no limit). Use the defined constants like FILE_SIZE_2MB
Return values
int —The result of the upload. This could be something like UPLOAD_SUCCESS or UPLOAD_ERROR_TOO_BIG
upload()
Uploads a file to an upload folder
public
upload(array<string|int, mixed> $file, string $uploadDir, int $maxSize, array<string|int, string> $typeArray) : int
This function will handle file uploads for you and make sure the type and the size are as defined. It also handles the movement to an upload folder. Be sure to change upload_max_filesize and post_max_size in you php.ini. It creates $uploadDir if missing and, on success, inserts a z_file row and fills ref, fileId and filePath; UPLOAD_SUCCESS is 0, so check errors with truthiness.
Parameters
- $file : array<string|int, mixed>
-
The $_FILES entry of the file. Example getFile("profile_picture")
- $uploadDir : string
-
The path to which the file will be uploaded
- $maxSize : int
-
The maximum size of the file in bytes (0 = no limit). Use the defined constants like FILE_SIZE_2MB
- $typeArray : array<string|int, string>
-
An array of allowed filetypes like ["jpg", "png"]
Return values
int —The result of the upload. This could be something like UPLOAD_SUCCESS or UPLOAD_ERROR_TOO_BIG
video()
Uploads a file, which must be a video (mp4, m4a, m4v, mov, 3gp, ogg, webm, flv, mkv, avi or wmv)
public
video(array<string|int, mixed> $file, string $uploadDir[, int $maxSize = FILE_SIZE_100MB ]) : int
An implementation of the upload method with a video filter. This function will handle file uploads for you and make sure the type and the size are as defined. It also handles the movement to an upload folder. Be sure to change upload_max_filesize and post_max_size in you php.ini
Parameters
- $file : array<string|int, mixed>
-
The $_FILES entry of the file. Example getFile("recording")
- $uploadDir : string
-
The path to which the file will be uploaded
- $maxSize : int = FILE_SIZE_100MB
-
The maximum size of the file in bytes (0 = no limit). Use the defined constants like FILE_SIZE_100MB
Return values
int —The result of the upload. This could be something like UPLOAD_SUCCESS or UPLOAD_ERROR_TOO_BIG