Upload
in package
HTTP server upload class
Tags
Table of Contents
Constants
- 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
Properties
- $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|null
- The upload directory path
- $uploadedFile : string|null
- The final filename of the uploaded file
Methods
- __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|null
- 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|null
$uploadDir
= null
$uploadedFile
The final filename of the uploaded file
protected
string|null
$uploadedFile
= null
Methods
__construct()
Constructor
public
__construct(string $dir[, int $maxSize = 0 ][, array<string|int, mixed>|null $disallowedTypes = null ][, array<string|int, mixed>|null $allowedTypes = null ]) : mixed
Instantiate a file upload object
Parameters
- $dir : string
- $maxSize : int = 0
- $disallowedTypes : array<string|int, mixed>|null = null
- $allowedTypes : array<string|int, mixed>|null = null
addAllowedType()
Add an allowed type
public
addAllowedType(string $type) : Upload
Parameters
- $type : string
Return values
UploadaddDisallowedType()
Add a disallowed type
public
addDisallowedType(string $type) : Upload
Parameters
- $type : string
Return values
UploadcheckDuplicate()
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
stringcheckFilename()
Check filename for duplicates, returning a new filename appended with _#
public
checkFilename(string $file) : string
Parameters
- $file : string
Return values
stringcreate()
Create an upload object
public
static create(string $dir[, int $maxSize = 0 ][, array<string|int, mixed>|null $disallowedTypes = null ][, array<string|int, mixed>|null $allowedTypes = null ]) : Upload
Parameters
- $dir : string
- $maxSize : int = 0
- $disallowedTypes : array<string|int, mixed>|null = null
- $allowedTypes : array<string|int, mixed>|null = null
Return values
UploaddoesFileExists()
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
boolfileExists()
Check if filename exists in the upload directory
public
fileExists(string $file) : bool
Parameters
- $file : string
Return values
boolgetAllowedTypes()
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
intgetErrorMessage()
Get the upload error message
public
getErrorMessage() : string
Return values
stringgetMaxSize()
Get the max size allowed
public
getMaxSize() : int
Return values
intgetUploadDir()
Get the upload directory
public
getUploadDir() : string
Return values
stringgetUploadedFile()
Get uploaded file
public
getUploadedFile() : string|null
Return values
string|nullgetUploadedFullPath()
Get uploaded file full path
public
getUploadedFullPath() : string
Return values
stringisAllowed()
Determine if a file type is allowed
public
isAllowed(string $ext) : bool
Parameters
- $ext : string
Return values
boolisError()
Determine if the upload was an error
public
isError() : bool
Return values
boolisNotAllowed()
Determine if a file type is not allowed
public
isNotAllowed(string $ext) : bool
Parameters
- $ext : string
Return values
boolisOverwrite()
Determine if the overwrite flag is set
public
isOverwrite() : bool
Return values
boolisSuccess()
Determine if the upload was a success
public
isSuccess() : bool
Return values
booloverwrite()
Set the overwrite flag
public
overwrite(bool $overwrite) : Upload
Parameters
- $overwrite : bool
Return values
UploadremoveAllowedType()
Remove an allowed type
public
removeAllowedType(string $type) : Upload
Parameters
- $type : string
Return values
UploadremoveDisallowedType()
Remove a disallowed type
public
removeDisallowedType(string $type) : Upload
Parameters
- $type : string
Return values
UploadsetAllowedTypes()
Set the allowed types
public
setAllowedTypes(array<string|int, mixed> $allowedTypes) : Upload
Parameters
- $allowedTypes : array<string|int, mixed>
Return values
UploadsetDefaults()
Set default file upload settings
public
setDefaults() : Upload
Return values
UploadsetDisallowedTypes()
Set the disallowed types
public
setDisallowedTypes(array<string|int, mixed> $disallowedTypes) : Upload
Parameters
- $disallowedTypes : array<string|int, mixed>
Return values
UploadsetMaxSize()
Set the upload directory
public
setMaxSize(int $maxSize) : Upload
Parameters
- $maxSize : int
Return values
UploadsetUploadDir()
Set the upload directory
public
setUploadDir(string $dir) : Upload
Parameters
- $dir : string
Return values
Uploadtest()
Test a file upload before moving it
public
test(array<string|int, mixed> $file) : bool
Parameters
- $file : array<string|int, mixed>
Return values
boolupload()
Upload file to the upload dir, returns the newly uploaded file
public
upload(array<string|int, mixed> $file[, string|null $to = null ][, bool $secure = true ]) : mixed
Parameters
- $file : array<string|int, mixed>
- $to : string|null = null
- $secure : bool = true