PHP Class Gdn_Upload, vanilla

Inheritance: extends Gdn_Pluggable
Afficher le fichier Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Свойство Type Description
$_AllowedFileExtensions array
$_MaxFileSize integer
$_UploadedFile string

Méthodes publiques

Méthode Description
__construct ( ) Class constructor.
allowFileExtension ( $Extension ) Adds an extension (or array of extensions) to the array of allowed file extensions.
canUpload ( null $UploadPath = null ) : boolean
clear ( )
copyLocal ( string $Name ) : string Copy an upload locally so that it can be operated on.
delete ( string $Name ) : boolean Delete an uploaded file.
formatFileSize ( integer $Bytes, integer $Precision = 1 ) : string Format a number of bytes with the largest unit.
generateTargetName ( $TargetFolder, string $Extension = 'jpg', boolean $Chunk = false ) : string
getUploadedFileExtension ( ) : mixed
getUploadedFileName ( ) : mixed
isUpload ( $inputName ) : boolean Check to see whether the user has selected a file for uploading.
isUploadUri ( string $uri ) : boolean Determine if a URI matches the format of a valid type/domain upload.
parse ( string $Name ) : array | boolean Parse a virtual filename that had previously been saved to the database.
saveAs ( $Source, $Target, array $Options = [] ) : array | boolean
unformatFileSize ( string $Formatted ) : integer Take a string formatted filesize and return the number of bytes.
url ( $Name ) : mixed
urls ( string $Type = null ) : string Returns the url prefix for a given type.
validateUpload ( $InputName, $ThrowException = true ) Validates the uploaded file. Returns the temporary name of the uploaded file.

Method Details

__construct() public méthode

Class constructor.
public __construct ( )

allowFileExtension() public méthode

Adds an extension (or array of extensions) to the array of allowed file extensions.
public allowFileExtension ( $Extension )

canUpload() public static méthode

public static canUpload ( null $UploadPath = null ) : boolean
$UploadPath null
Résultat boolean

clear() public méthode

public clear ( )

copyLocal() public méthode

Copy an upload locally so that it can be operated on.
public copyLocal ( string $Name ) : string
$Name string Filename to be copied.
Résultat string Local file path.

delete() public méthode

Delete an uploaded file.
public delete ( string $Name ) : boolean
$Name string The name of the upload as saved in the database.
Résultat boolean

formatFileSize() public static méthode

Format a number of bytes with the largest unit.
public static formatFileSize ( integer $Bytes, integer $Precision = 1 ) : string
$Bytes integer The number of bytes.
$Precision integer The number of decimal places in the formatted number.
Résultat string the formatted filesize.

generateTargetName() public méthode

public generateTargetName ( $TargetFolder, string $Extension = 'jpg', boolean $Chunk = false ) : string
$TargetFolder
$Extension string
$Chunk boolean
Résultat string

getUploadedFileExtension() public méthode

public getUploadedFileExtension ( ) : mixed
Résultat mixed

getUploadedFileName() public méthode

public getUploadedFileName ( ) : mixed
Résultat mixed

isUpload() public méthode

Check to see whether the user has selected a file for uploading.
public isUpload ( $inputName ) : boolean
$inputName The input name of the file.
Résultat boolean Whether a file has been selected for the fiels.

isUploadUri() public static méthode

Determine if a URI matches the format of a valid type/domain upload.
public static isUploadUri ( string $uri ) : boolean
$uri string The URI to test. This would be the value saved in the database (ex. GDN_User.Photo).
Résultat boolean Returns **true** if {@link uri} looks like an uploaded file or **false** otherwise.

parse() public static méthode

There are various formats supported for the name, mostly due to legacy concerns. - http(s)://domain/path.ext: A fully qualified url. - /path/from/uploads.ext: This is a locally uploaded file. - /path/to/uploads/path.ext: A full path starting from the uploads directory (deprecated). - ~type/path.ext: A specific type of upload provided by a plugin (deprecated). - type://domain/path.ext: A specific type of upload provied by a plugin with additional domain information.
public static parse ( string $Name ) : array | boolean
$Name string The virtual name of the file.
Résultat array | boolean Returns an array of parsed information or false if the parse failed.

saveAs() public méthode

public saveAs ( $Source, $Target, array $Options = [] ) : array | boolean
$Source
$Target
$Options array
Résultat array | boolean

unformatFileSize() public static méthode

Take a string formatted filesize and return the number of bytes.
public static unformatFileSize ( string $Formatted ) : integer
$Formatted string The formatted filesize.
Résultat integer The number of bytes in the string.

url() public static méthode

public static url ( $Name ) : mixed
$Name
Résultat mixed

urls() public static méthode

If there is a plugin that wants to store uploads at a different location or in a different way then they register themselves by subscribing to the Gdn_Upload_GetUrls_Handler event. After that they will be available here.
public static urls ( string $Type = null ) : string
$Type string The type of upload to get the prefix for.
Résultat string The url prefix.

validateUpload() public méthode

Validates the uploaded file. Returns the temporary name of the uploaded file.
public validateUpload ( $InputName, $ThrowException = true )

Property Details

$_AllowedFileExtensions protected_oe property

protected array $_AllowedFileExtensions
Résultat array

$_MaxFileSize protected_oe property

protected int $_MaxFileSize
Résultat integer

$_UploadedFile protected_oe property

protected string $_UploadedFile
Résultat string