Ubiquity 2.5.2
php rapid development framework
Loading...
Searching...
No Matches
UFilesUpload Class Reference

File Uploader class utility. More...

Public Member Functions

 __construct ($destDir='upload')
 
 setUploadOptions (?array $allowedMimeTypes=null, int $maxFileSize=100000)
 
 getMaxFileSize ()
 
 setMaxFileSize (int $maxFileSize)
 
 getAllowedMimeTypes ()
 
 setAllowedMimeTypes (?array $allowedMimeTypes)
 
 allowImages (bool $only=true)
 
 allowAllMimeTypes ()
 
 setMessageTypes (array $messages)
 Redefine the messages displayed.
 
 getMessageTypes ()
 Get the message types displayed.
 
 upload (string $destDir=null, bool $force=true,?callable $filenameCallback=null)
 Uploads files to $destDir directory.
 
 hasErrors ()
 Returns true if the upload generated at least one error.
 
 isSuccess ()
 Returns true if at least one file has been uploaded.
 
 getMessages ()
 Returns all success messages.
 
 getErrorMessages ()
 Returns all error messages.
 

Data Fields

const SUCCESS_MESSAGE ='uploadSuccess'
 
const NO_FILE_SENT_ERR ='uploadNoFileSentErr'
 
const FILE_SIZE_ERR ='uploadFileSizeErr'
 
const UNKNOWN_ERR ='uploadUnknownErr'
 
const MIME_TYPE_ERR ='uploadMimeTypeErr'
 
const EXISTING_FILE_ERR ='uploadExistingFileErr'
 
const UPLOAD_ERR ='uploadErr'
 
const INVALID_FORMAT_ERR ='uploadInvalidFormatErr'
 

Private Member Functions

 allowType (bool $only, array $typeArray)
 
 checkErrors (array $file)
 
 getMessageType (string $type, string ... $params)
 
 checkTypeMime (array $file)
 
 checkFileSize (array $file)
 
 getDisplayedFileName (array $file)
 

Private Attributes

const IMAGES_MIME_TYPES =['bmp'=>'image/bmp','gif'=>'image/gif','ico'=>'image/vnd.microsoft.icon','jpg'=>'image/jpeg','jpeg'=>'image/jpeg','svg'=>'image/svg+xml','png'=>'image/png','tif'=>'image/tiff','tiff'=>'image/tiff']
 
int $maxFileSize =100000
 
array $allowedMimeTypes =['pdf'=>'application/pdf']
 
array $messages
 
string $destDir
 
array $messageTypes
 

Detailed Description

File Uploader class utility.

Ubiquity\utils\http$UFilesUpload This class is part of Ubiquity

Author
jcheron myadd.nosp@m.ress.nosp@m.mail@.nosp@m.gmai.nosp@m.l.com
Version
0.0.0

Definition at line 19 of file UFilesUpload.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $destDir = 'upload')

Definition at line 46 of file UFilesUpload.php.

Member Function Documentation

◆ allowAllMimeTypes()

allowAllMimeTypes ( )

Definition at line 91 of file UFilesUpload.php.

◆ allowImages()

allowImages ( bool  $only = true)

Definition at line 87 of file UFilesUpload.php.

◆ allowType()

allowType ( bool  $only,
array  $typeArray 
)
private

Definition at line 95 of file UFilesUpload.php.

◆ checkErrors()

checkErrors ( array  $file)
private

Definition at line 103 of file UFilesUpload.php.

◆ checkFileSize()

checkFileSize ( array  $file)
private

Definition at line 136 of file UFilesUpload.php.

◆ checkTypeMime()

checkTypeMime ( array  $file)
private

Definition at line 124 of file UFilesUpload.php.

◆ getAllowedMimeTypes()

getAllowedMimeTypes ( )
Returns
array|string[]|null

Definition at line 76 of file UFilesUpload.php.

◆ getDisplayedFileName()

getDisplayedFileName ( array  $file)
private

Definition at line 144 of file UFilesUpload.php.

◆ getErrorMessages()

getErrorMessages ( )

Returns all error messages.

Returns
array|mixed

Definition at line 228 of file UFilesUpload.php.

◆ getMaxFileSize()

getMaxFileSize ( )
Returns
int

Definition at line 62 of file UFilesUpload.php.

◆ getMessages()

getMessages ( )

Returns all success messages.

Returns
array|mixed

Definition at line 220 of file UFilesUpload.php.

◆ getMessageType()

getMessageType ( string  $type,
string ...  $params 
)
private

Definition at line 120 of file UFilesUpload.php.

◆ getMessageTypes()

getMessageTypes ( )

Get the message types displayed.

Returns
array

Definition at line 160 of file UFilesUpload.php.

◆ hasErrors()

hasErrors ( )

Returns true if the upload generated at least one error.

Returns
bool

Definition at line 204 of file UFilesUpload.php.

◆ isSuccess()

isSuccess ( )

Returns true if at least one file has been uploaded.

Returns
bool

Definition at line 212 of file UFilesUpload.php.

◆ setAllowedMimeTypes()

setAllowedMimeTypes ( ?array  $allowedMimeTypes)
Parameters
array | string[] | null$allowedMimeTypes

Definition at line 83 of file UFilesUpload.php.

◆ setMaxFileSize()

setMaxFileSize ( int  $maxFileSize)
Parameters
int$maxFileSize

Definition at line 69 of file UFilesUpload.php.

◆ setMessageTypes()

setMessageTypes ( array  $messages)

Redefine the messages displayed.

Parameters
array$messages

Definition at line 152 of file UFilesUpload.php.

◆ setUploadOptions()

setUploadOptions ( ?array  $allowedMimeTypes = null,
int  $maxFileSize = 100000 
)
Parameters
array | null$allowedMimeTypes
int$maxFileSize

Definition at line 54 of file UFilesUpload.php.

◆ upload()

upload ( string  $destDir = null,
bool  $force = true,
?callable  $filenameCallback = null 
)

Uploads files to $destDir directory.

Parameters
string | null$destDiris relative to ROOT app
bool$forceif True, replace existing files
callable | null$fileNameCallbackreturns an updated version of the dest filename i.e. function($filename){ return '_'.$filename;}

Definition at line 170 of file UFilesUpload.php.

Field Documentation

◆ $allowedMimeTypes

array $allowedMimeTypes =['pdf'=>'application/pdf']
private

Definition at line 32 of file UFilesUpload.php.

◆ $destDir

string $destDir
private

Definition at line 34 of file UFilesUpload.php.

◆ $maxFileSize

int $maxFileSize =100000
private

Definition at line 31 of file UFilesUpload.php.

◆ $messages

array $messages
private

Definition at line 33 of file UFilesUpload.php.

◆ $messageTypes

array $messageTypes
private
Initial value:
=[
self::SUCCESS_MESSAGE=>'The file %s has been uploaded.',
self::NO_FILE_SENT_ERR=>'No file sent.',
self::FILE_SIZE_ERR=>'Exceeded file size limit for %s.',
self::UNKNOWN_ERR=>'Unknown Error.',
self::MIME_TYPE_ERR=>'The mime-type %s is not allowed for %s!',
self::EXISTING_FILE_ERR=>'Sorry, The file %s already exists.',
self::UPLOAD_ERR=>'Sorry, there was an error uploading the file %s.',
self::INVALID_FORMAT_ERR=>'Invalid error format!'
]

Definition at line 35 of file UFilesUpload.php.

◆ EXISTING_FILE_ERR

const EXISTING_FILE_ERR ='uploadExistingFileErr'

Definition at line 25 of file UFilesUpload.php.

◆ FILE_SIZE_ERR

const FILE_SIZE_ERR ='uploadFileSizeErr'

Definition at line 22 of file UFilesUpload.php.

◆ IMAGES_MIME_TYPES

const IMAGES_MIME_TYPES =['bmp'=>'image/bmp','gif'=>'image/gif','ico'=>'image/vnd.microsoft.icon','jpg'=>'image/jpeg','jpeg'=>'image/jpeg','svg'=>'image/svg+xml','png'=>'image/png','tif'=>'image/tiff','tiff'=>'image/tiff']
private

Definition at line 29 of file UFilesUpload.php.

◆ INVALID_FORMAT_ERR

const INVALID_FORMAT_ERR ='uploadInvalidFormatErr'

Definition at line 27 of file UFilesUpload.php.

◆ MIME_TYPE_ERR

const MIME_TYPE_ERR ='uploadMimeTypeErr'

Definition at line 24 of file UFilesUpload.php.

◆ NO_FILE_SENT_ERR

const NO_FILE_SENT_ERR ='uploadNoFileSentErr'

Definition at line 21 of file UFilesUpload.php.

◆ SUCCESS_MESSAGE

const SUCCESS_MESSAGE ='uploadSuccess'

Definition at line 20 of file UFilesUpload.php.

◆ UNKNOWN_ERR

const UNKNOWN_ERR ='uploadUnknownErr'

Definition at line 23 of file UFilesUpload.php.

◆ UPLOAD_ERR

const UPLOAD_ERR ='uploadErr'

Definition at line 26 of file UFilesUpload.php.


The documentation for this class was generated from the following file: