Upload
in package
HTTP server upload class
Tags
Table of Contents
- UPLOAD_ERR_DIR_NOT_EXIST = 11
- Upload directory does not exist
- UPLOAD_ERR_DIR_NOT_WRITABLE = 12
- Upload directory not writable
- UPLOAD_ERR_FILE_NOT_SECURE = 13
- File security error
- UPLOAD_ERR_NOT_ALLOWED = 10
- File is not allowed, per user-definition
- UPLOAD_ERR_UNEXPECTED = 14
- Unexpected error
- UPLOAD_ERR_USER_SIZE = 9
- File is too big by the user-defined max size
- $allowedTypes : array<string|int, mixed>
- Allowed file types
- $disallowedTypes : array<string|int, mixed>
- Disallowed file types
- $error : int
- Error flag
- $errorMessages : array<string|int, mixed>
- Error messageed
- $maxSize : int
- Allowed maximum file size
- $overwrite : bool
- Overwrite flag
- $uploadDir : string
- The upload directory path
- $uploadedFile : string
- The final filename of the uploaded file
- __construct() : mixed
- Constructor
- addAllowedType() : Upload
- Add an allowed type
- addDisallowedType() : Upload
- Add a disallowed type
- checkDuplicate() : string
- Check for a duplicate filename in the upload directory, and return a modified filename if it exists already
- checkFilename() : string
- Check filename for duplicates, returning a new filename appended with _#
- create() : Upload
- Create an upload object
- doesFileExists() : bool
- Check if the file exists already in the upload directory
- fileExists() : bool
- Check if filename exists in the upload directory
- getAllowedTypes() : array<string|int, mixed>
- Get the allowed file types
- getDisallowedTypes() : array<string|int, mixed>
- Get the disallowed file types
- getErrorCode() : int
- Get the upload error code
- getErrorMessage() : string
- Get the upload error message
- getMaxSize() : int
- Get the max size allowed
- getUploadDir() : string
- Get the upload directory
- getUploadedFile() : string
- Get uploaded file
- getUploadedFullPath() : string
- Get uploaded file full path
- isAllowed() : bool
- Determine if a file type is allowed
- isError() : bool
- Determine if the upload was an error
- isNotAllowed() : bool
- Determine if a file type is not allowed
- isOverwrite() : bool
- Determine if the overwrite flag is set
- isSuccess() : bool
- Determine if the upload was a success
- overwrite() : Upload
- Set the overwrite flag
- removeAllowedType() : Upload
- Remove an allowed type
- removeDisallowedType() : Upload
- Remove a disallowed type
- setAllowedTypes() : Upload
- Set the allowed types
- setDefaults() : Upload
- Set default file upload settings
- setDisallowedTypes() : Upload
- Set the disallowed types
- setMaxSize() : Upload
- Set the upload directory
- setUploadDir() : Upload
- Set the upload directory
- test() : bool
- Test a file upload before moving it
- upload() : mixed
- Upload file to the upload dir, returns the newly uploaded file
Constants
UPLOAD_ERR_DIR_NOT_EXIST
Upload directory does not exist
public
mixed
UPLOAD_ERR_DIR_NOT_EXIST
= 11
UPLOAD_ERR_DIR_NOT_WRITABLE
Upload directory not writable
public
mixed
UPLOAD_ERR_DIR_NOT_WRITABLE
= 12
UPLOAD_ERR_FILE_NOT_SECURE
File security error
public
mixed
UPLOAD_ERR_FILE_NOT_SECURE
= 13
UPLOAD_ERR_NOT_ALLOWED
File is not allowed, per user-definition
public
mixed
UPLOAD_ERR_NOT_ALLOWED
= 10
UPLOAD_ERR_UNEXPECTED
Unexpected error
public
mixed
UPLOAD_ERR_UNEXPECTED
= 14
UPLOAD_ERR_USER_SIZE
File is too big by the user-defined max size
public
mixed
UPLOAD_ERR_USER_SIZE
= 9
Properties
$allowedTypes
Allowed file types
protected
array<string|int, mixed>
$allowedTypes
= []
$disallowedTypes
Disallowed file types
protected
array<string|int, mixed>
$disallowedTypes
= []
$error
Error flag
protected
int
$error
= 0
$errorMessages
Error messageed
protected
static array<string|int, mixed>
$errorMessages
= [0 => 'The file uploaded successfully', 1 => 'The uploaded file exceeds the upload_max_filesize directive', 2 => 'The uploaded file exceeds the MAX_FILE_SIZE directive in the HTML form', 3 => 'The uploaded file was only partially uploaded', 4 => 'No file was uploaded', 6 => 'Missing a temporary folder', 7 => 'Failed to write file to disk', 8 => 'A PHP extension stopped the file upload', 9 => 'The uploaded file exceeds the user-defined max file size', 10 => 'The uploaded file is not allowed', 11 => 'The specified upload directory does not exist', 12 => 'The specified upload directory is not writable', 13 => 'The uploaded file was not uploaded securely', 14 => 'Unexpected error']
$maxSize
Allowed maximum file size
protected
int
$maxSize
= 0
$overwrite
Overwrite flag
protected
bool
$overwrite
= false
$uploadDir
The upload directory path
protected
string
$uploadDir
= null
$uploadedFile
The final filename of the uploaded file
protected
string
$uploadedFile
= null
Methods
__construct()
Constructor
public
__construct(string $dir, int $maxSize[, array<string|int, mixed> $disallowedTypes = null ][, array<string|int, mixed> $allowedTypes = null ]) : mixed
Instantiate a file upload object
Parameters
- $dir : string
- $maxSize : int
- $disallowedTypes : array<string|int, mixed> = null
- $allowedTypes : array<string|int, mixed> = null
Return values
mixed —addAllowedType()
Add an allowed type
public
addAllowedType(string $type) : Upload
Parameters
- $type : string
Return values
Upload —addDisallowedType()
Add a disallowed type
public
addDisallowedType(string $type) : Upload
Parameters
- $type : string
Return values
Upload —checkDuplicate()
Check for a duplicate filename in the upload directory, and return a modified filename if it exists already
public
static checkDuplicate(string $dir, string $file) : string
Parameters
- $dir : string
- $file : string
Return values
string —checkFilename()
Check filename for duplicates, returning a new filename appended with _#
public
checkFilename(string $file) : string
Parameters
- $file : string
Return values
string —create()
Create an upload object
public
static create(string $dir, int $maxSize[, array<string|int, mixed> $disallowedTypes = null ][, array<string|int, mixed> $allowedTypes = null ]) : Upload
Parameters
- $dir : string
- $maxSize : int
- $disallowedTypes : array<string|int, mixed> = null
- $allowedTypes : array<string|int, mixed> = null
Return values
Upload —doesFileExists()
Check if the file exists already in the upload directory
public
static doesFileExists(string $dir, string $file) : bool
Parameters
- $dir : string
- $file : string
Return values
bool —fileExists()
Check if filename exists in the upload directory
public
fileExists(string $file) : bool
Parameters
- $file : string
Return values
bool —getAllowedTypes()
Get the allowed file types
public
getAllowedTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —getDisallowedTypes()
Get the disallowed file types
public
getDisallowedTypes() : array<string|int, mixed>
Return values
array<string|int, mixed> —getErrorCode()
Get the upload error code
public
getErrorCode() : int
Return values
int —getErrorMessage()
Get the upload error message
public
getErrorMessage() : string
Return values
string —getMaxSize()
Get the max size allowed
public
getMaxSize() : int
Return values
int —getUploadDir()
Get the upload directory
public
getUploadDir() : string
Return values
string —getUploadedFile()
Get uploaded file
public
getUploadedFile() : string
Return values
string —getUploadedFullPath()
Get uploaded file full path
public
getUploadedFullPath() : string
Return values
string —isAllowed()
Determine if a file type is allowed
public
isAllowed(string $ext) : bool
Parameters
- $ext : string
Return values
bool —isError()
Determine if the upload was an error
public
isError() : bool
Return values
bool —isNotAllowed()
Determine if a file type is not allowed
public
isNotAllowed(string $ext) : bool
Parameters
- $ext : string
Return values
bool —isOverwrite()
Determine if the overwrite flag is set
public
isOverwrite() : bool
Return values
bool —isSuccess()
Determine if the upload was a success
public
isSuccess() : bool
Return values
bool —overwrite()
Set the overwrite flag
public
overwrite(bool $overwrite) : Upload
Parameters
- $overwrite : bool
Return values
Upload —removeAllowedType()
Remove an allowed type
public
removeAllowedType(string $type) : Upload
Parameters
- $type : string
Return values
Upload —removeDisallowedType()
Remove a disallowed type
public
removeDisallowedType(string $type) : Upload
Parameters
- $type : string
Return values
Upload —setAllowedTypes()
Set the allowed types
public
setAllowedTypes(array<string|int, mixed> $allowedTypes) : Upload
Parameters
- $allowedTypes : array<string|int, mixed>
Return values
Upload —setDefaults()
Set default file upload settings
public
setDefaults() : Upload
Return values
Upload —setDisallowedTypes()
Set the disallowed types
public
setDisallowedTypes(array<string|int, mixed> $disallowedTypes) : Upload
Parameters
- $disallowedTypes : array<string|int, mixed>
Return values
Upload —setMaxSize()
Set the upload directory
public
setMaxSize(int $maxSize) : Upload
Parameters
- $maxSize : int
Return values
Upload —setUploadDir()
Set the upload directory
public
setUploadDir(string $dir) : Upload
Parameters
- $dir : string
Return values
Upload —test()
Test a file upload before moving it
public
test(array<string|int, mixed> $file) : bool
Parameters
- $file : array<string|int, mixed>
Return values
bool —upload()
Upload file to the upload dir, returns the newly uploaded file
public
upload(array<string|int, mixed> $file[, string $to = null ][, bool $secure = true ]) : mixed
Parameters
- $file : array<string|int, mixed>
- $to : string = null
- $secure : bool = true