CUploadedFile represents the information for an uploaded file.
Call CUploadedFile::getInstance()
to retrieve the instance of an uploaded file, and
then use CUploadedFile::saveAs()
to save it on the server. You may also query other
information about the file, including name, tempName, type, size and error.
Methods summary
public static
CUploadedFile
|
#
getInstance( CModel $model, string $attribute )
Returns an instance of the specified uploaded file. The file should be
uploaded using CHtml::activeFileField() .
Parameters
- $model
CModel
$model the model instance
- $attribute
string $attribute the attribute name. For tabular file uploading, this can be in the
format of "[$i]attributeName", where $i stands for an integer index.
Returns
CUploadedFile
the instance of the uploaded file. Null is returned if no file is uploaded for
the specified model attribute.
See
|
public static
CUploadedFile[]
|
#
getInstances( CModel $model, string $attribute )
Returns all uploaded files for the given model attribute.
Returns all uploaded files for the given model attribute.
Parameters
- $model
CModel
$model the model instance
- $attribute
string $attribute the attribute name. For tabular file uploading, this can be in the
format of "[$i]attributeName", where $i stands for an integer index.
Returns
CUploadedFile[]
array of CUploadedFile objects. Empty array is returned if no available file was
found for the given attribute.
|
public static
CUploadedFile
|
#
getInstanceByName( string $name )
Returns an instance of the specified uploaded file. The name can be a plain
string or a string like an array element (e.g. 'Post[imageFile]', or
'Post[0][imageFile]').
Returns an instance of the specified uploaded file. The name can be a plain
string or a string like an array element (e.g. 'Post[imageFile]', or
'Post[0][imageFile]').
Parameters
- $name
string $name the name of the file input field.
Returns
CUploadedFile
the instance of the uploaded file. Null is returned if no file is uploaded for
the specified name.
|
public static
CUploadedFile[]
|
#
getInstancesByName( string $name )
Returns an array of instances starting with specified array name.
Returns an array of instances starting with specified array name.
If multiple files were uploaded and saved as 'Files[0]', 'Files[1]',
'Files[n]'..., you can have them all by passing 'Files' as array name.
Parameters
- $name
string $name the name of the array of files
Returns
CUploadedFile[]
the array of CUploadedFile objects. Empty array is returned if no adequate
upload was found. Please note that this array will contain all files from all
subarrays regardless how deeply nested they are.
|
public static
|
#
reset( )
Cleans up the loaded CUploadedFile instances. This method is mainly used by
test scripts to set up a fixture.
Cleans up the loaded CUploadedFile instances. This method is mainly used by
test scripts to set up a fixture.
Since
1.1.4
|
protected static
|
#
prefetchFiles( )
Initially processes $_FILES superglobal for easier use. Only for internal
usage.
Initially processes $_FILES superglobal for easier use. Only for internal
usage.
|
protected static
|
#
collectFilesRecursive( string $key, mixed $names, mixed $tmp_names, mixed $types, mixed $sizes, mixed $errors )
Processes incoming files for CUploadedFile::getInstanceByName() .
Parameters
- $key
string $key key for identifiing uploaded file: class name and subarray indexes
- $names
mixed $names file names provided by PHP
- $tmp_names
mixed $tmp_names temporary file names provided by PHP
- $types
mixed $types filetypes provided by PHP
- $sizes
mixed $sizes file sizes provided by PHP
- $errors
mixed $errors uploading issues provided by PHP
|
public
|
#
__construct( string $name, string $tempName, string $type, integer $size, integer $error )
Constructor. Use CUploadedFile::getInstance() to get an instance of an uploaded
file.
Parameters
- $name
string $name the original name of the file being uploaded
- $tempName
string $tempName the path of the uploaded file on the server.
- $type
string $type the MIME-type of the uploaded file (such as "image/gif").
- $size
integer $size the actual size of the uploaded file in bytes
- $error
integer $error the error code
|
public
string
|
#
__toString( )
String output. This is PHP magic method that returns string representation of
an object. The implementation here returns the uploaded file's name.
String output. This is PHP magic method that returns string representation of
an object. The implementation here returns the uploaded file's name.
Returns
string the string representation of the object
|
public
boolean
|
#
saveAs( string $file, boolean $deleteTempFile = true )
Saves the uploaded file. Note: this method uses php's move_uploaded_file()
method. As such, if the target file ($file) already exists it is
overwritten.
Saves the uploaded file. Note: this method uses php's move_uploaded_file()
method. As such, if the target file ($file) already exists it is
overwritten.
Parameters
- $file
string $file the file path used to save the uploaded file
- $deleteTempFile
boolean $deleteTempFile whether to delete the temporary file after saving. If true, you
will not be able to save the uploaded file again in the current request.
Returns
boolean true whether the file is saved successfully
|
public
string
|
#
getName( )
Returns
string the original name of the file being uploaded
|
public
string
|
#
getTempName( )
Returns
string the path of the uploaded file on the server. Note, this is a temporary file
which will be automatically deleted by PHP after the current request is
processed.
|
public
string
|
#
getType( )
Returns
string the MIME-type of the uploaded file (such as "image/gif"). Since this MIME type
is not checked on the server side, do not take this value for granted. Instead,
use CFileHelper::getMimeType() to determine the exact MIME type.
|
public
integer
|
#
getSize( )
Returns
integer the actual size of the uploaded file in bytes
|
public
integer
|
#
getError( )
Returns an error code describing the status of this file uploading.
Returns an error code describing the status of this file uploading.
Returns
integer the error code
See
|
public
boolean
|
#
getHasError( )
Returns
boolean whether there is an error with the uploaded file. Check error for
detailed error code information.
|
public
string
|
#
getExtensionName( )
Returns
string the file extension name for name. The extension name does not include
the dot character. An empty string is returned if name does not have an
extension name.
|
Magic properties summary
public
string
|
$name
|
#
The original name of the file being uploaded.
The original name of the file being uploaded.
|
public
string
|
$tempName
|
#
The path of the uploaded file on the server. Note, this is a temporary file
which will be automatically deleted by PHP after the current request is
processed.
The path of the uploaded file on the server. Note, this is a temporary file
which will be automatically deleted by PHP after the current request is
processed.
|
public
string
|
$type
|
#
The MIME-type of the uploaded file (such as "image/gif"). Since this MIME
type is not checked on the server side, do not take this value for granted.
Instead, use CFileHelper::getMimeType() to determine the exact MIME
type.
The MIME-type of the uploaded file (such as "image/gif"). Since this MIME
type is not checked on the server side, do not take this value for granted.
Instead, use CFileHelper::getMimeType() to determine the exact MIME
type.
|
public
integer
|
$size
|
#
The actual size of the uploaded file in bytes.
The actual size of the uploaded file in bytes.
|
public
integer
|
$error
|
|
public
boolean
|
$hasError
|
#
Whether there is an error with the uploaded file. Check error for
detailed error code information.
Whether there is an error with the uploaded file. Check error for
detailed error code information.
|
public
string
|
$extensionName
|
#
The file extension name for name. The extension name does not include
the dot character. An empty string is returned if name does not have an
extension name.
The file extension name for name. The extension name does not include
the dot character. An empty string is returned if name does not have an
extension name.
|