PHP Class Gdn_Upload, vanilla

Inheritance: extends Gdn_Pluggable
Mostrar archivo Open project: vanilla/vanilla Class Usage Examples

Protected Properties

Property Type Description
$_AllowedFileExtensions array
$_MaxFileSize integer
$_UploadedFile string

Public Methods

Method 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 method

Class constructor.
public __construct ( )

allowFileExtension() public method

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

canUpload() public static method

public static canUpload ( null $UploadPath = null ) : boolean
$UploadPath null
return boolean

clear() public method

public clear ( )

copyLocal() public method

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

delete() public method

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

formatFileSize() public static method

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.
return string the formatted filesize.

generateTargetName() public method

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

getUploadedFileExtension() public method

public getUploadedFileExtension ( ) : mixed
return mixed

getUploadedFileName() public method

public getUploadedFileName ( ) : mixed
return mixed

isUpload() public method

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

isUploadUri() public static method

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).
return boolean Returns **true** if {@link uri} looks like an uploaded file or **false** otherwise.

parse() public static method

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.
return array | boolean Returns an array of parsed information or false if the parse failed.

saveAs() public method

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

unformatFileSize() public static method

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

url() public static method

public static url ( $Name ) : mixed
$Name
return mixed

urls() public static method

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.
return string The url prefix.

validateUpload() public method

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
return array

$_MaxFileSize protected_oe property

protected int $_MaxFileSize
return integer

$_UploadedFile protected_oe property

protected string $_UploadedFile
return string