Upload component
Simplifies the file upload and storage for files added to the filesystem
Requires the Input Component
public
|
|
public
|
#
setFiles( array $files, boolean $uploaded_files = true )
Sets the array of files to be considered for handling. This class
automatically defaults the set of arrays to the global FILES array
Sets the array of files to be considered for handling. This class
automatically defaults the set of arrays to the global FILES array
Parameters
- $files
array $files An array of files from the global FILES array to set. The format of this
array must match that the global FILES array exactly
- $uploaded_files
boolean $uploaded_file If true the file was uploaded, false if the file was created and
not uploaded
|
public
|
#
setUploadPath( string $path, mixed $create = false )
Sets the upload path. The upload path will be verified when files are
written. If the upload path is invalid file uploads will result in errors
Sets the upload path. The upload path will be verified when files are
written. If the upload path is invalid file uploads will result in errors
Parameters
- $path
string $path The server path to where files are to be written
- $create
|
public
|
#
setMaxFileSize( integer $bytes = 0 )
Sets the maximum file size in bytes. The server may have its own setting for
maximum file sizes, so ensure that this value does not exceede the server's
allowed maximum size
Sets the maximum file size in bytes. The server may have its own setting for
maximum file sizes, so ensure that this value does not exceede the server's
allowed maximum size
Parameters
- $bytes
integer $bytes The maximum file size in bytes. Set to 0 to use no maximum file size.
|
public
|
#
setAllowedMimeTypes( array $types = null )
Sets the allowed MIME types
Sets the allowed MIME types
Parameters
- $types
array $types An array of MIME types to allow, set to null to allow all MIME types
|
public
|
#
writeFile( string $file, boolean $overwrite = true, string $file_name = null, callable $rename_callback = null, integer $permissions = 0644 )
Writes one or more files to the file system. Because of the nature of writing
files to the disk, if any file fails execution will continue. Any failed files
will be reported by Upload::errors()
Writes one or more files to the file system. Because of the nature of writing
files to the disk, if any file fails execution will continue. Any failed files
will be reported by Upload::errors()
Parameters
- $file
string $file A field name to search the global file variable for
- $overwrite
boolean $overwrite Whether or not to overwrite the file if it already exists
- $file_name
string $file_name The name of the file to use instead of the uploaded file's name, null
to use uploaded file's name
- $rename_callback
callable $rename_callback A callback to execute used to rename the file
- $permissions
integer $permissions The permission value in octets, null to default to user permissions
|
public
|
#
writeFiles( array $files, boolean $overwrite = true, array $file_names = null, callable $rename_callback = null, integer $permissions = 0644 )
Writes multiple files to the file system. Because of the nature of writing
files to the disk, if any file fails execution will continue. Any failed files
will be reported by Upload::errors()
Writes multiple files to the file system. Because of the nature of writing
files to the disk, if any file fails execution will continue. Any failed files
will be reported by Upload::errors()
Parameters
- $files
array $files An array of file field names to search the global file variable for
- $overwrite
boolean $overwrite Whether or not to overwrite the file if it already exists
- $file_names
array $file_names The names of the files to use instead of the uploaded file's name,
null to use uploaded file's name
- $rename_callback
callable $rename_callback A callback to execute used to rename the file
- $permissions
integer $permissions The permission value in octets, null to default to user permissions
|
public
array
|
#
getUploadData( )
Fetches the upload data
Returns
array An array of upload data for each of the uploaded files including: - orig_name
The original name of the uploaded file - file_name The new file name - file_path
The path where the file was written - full_path The full path to the file that
was written - file_size The size of the file that was written (in bytes)
|
public
|
#
createUploadPath( string $path, integer $permissions = 0755 )
Recursively creates the upload path if it does not already exists. Also sets
permissions to the given set when the directory is created
Recursively creates the upload path if it does not already exists. Also sets
permissions to the given set when the directory is created
Parameters
- $path
string $path The directory path to create
- $permissions
integer $permissions The permission value in octets
|
public
array
|
#
errors( )
Returns all errors set
Returns
array An array of errors set in Input
|
public
string
|
#
appendCount( string $file_name )
Returns a suggested file name with a number appended at the end so that it is
unique in the upload path
Returns a suggested file name with a number appended at the end so that it is
unique in the upload path
Parameters
- $file_name
string $file_name The name of the file to append a count to
Returns
string The suggested file name
|
public
string
|
#
md5( mixed $file_name )
Returns a suggested file name that uses an MD5 hash of the existing file name
while preserving the file extension. For example my_file.txt becomes
3715ac9af3d0d8cb0970e08494034357.txt, that is md5(my_file.txt) with .txt
appended.
Returns a suggested file name that uses an MD5 hash of the existing file name
while preserving the file extension. For example my_file.txt becomes
3715ac9af3d0d8cb0970e08494034357.txt, that is md5(my_file.txt) with .txt
appended.
Returns
string The suggested file name
|