Simplified wrapper for file uploading.
package | dstruct_filetools |
---|---|
author | David Lidstone |
__construct()
contentType(string $key) : string
string
{@link setDefault()}
string
count() : integer
Files with 0 size are NOT counted.
integer
exists(string $key) : boolean
The key is the internal 'name' of the file - usually specified by the name attribute of your form's file element
string
{@link setDefault()}
boolean
extension(string $key) : string
string
{@link setDefault()}
string
fullName(string $key) : string
string
{@link setDefault()}
string
getDefault() : string
The default file will be the first file uploaded or the file manually set to default. The key is used by other methods of this class.
see | \setDefault() |
---|
string
getErrorMessage(string $key) : string
string
{@link setDefault()}
string
getErrorNumber(string $key) : integer
string
{@link setDefault()}
integer
getFileRequired() : boolean
getNewName() : string
getOverwriteChar() : string
getOverwriteMode() : integer
getSavePath() : string
getTempFile(string $key) : string
string
{@link setDefault()}
string
getUploadErrors() : array
isAllowableType(string $key) : boolean
Checks both extension and mime against any provided arrays: setAllowableTypes
string
{@link setDefault()}
boolean
isError(string $key) : boolean
Return depends on whether an uploaded file is required. See setFileRequired().
string
{@link setDefault()}
boolean
nameOnly(string $key) : string
string
{@link setDefault()}
string
save(string $key) : boolean
todo | Should throw a descriptive error if can not save |
---|
string
{@link setDefault()}
boolean
True on successsetAllowableTypes(array $mimes, array $extns)
Types must be in lower-case for the comparision to work
array
Allowable Mime-Types
array
Allowable file-extensions
setDefault(string $key) : boolean
For example, if your form field is 'userfile', you can set this to 'userfile' and not need to keep supplying a key.
string
boolean
False if no file by that name existssetFileRequired(boolean $bln)
setNewName(string $name)
The file name is usually preserved if a file by that name is not already present (@see setOverwriteMode()}. This allows setting of the name manually before saving. Use the full name, excluding the extension.
string
setOverwriteChar(string $char)
If setOverwriteMode() is set to OVERWRITE_APPEND, files
are not overwritten but have this overwrite character and a number
appened to the file name. Default is _ (underscore).
Be wary of restrictions due to operating systems.
string
setOverwriteMode(integer $mode)
Overwrite can be one of OVERWRITE_NO, OVERWRITE_YES or OVERWRITE_APPEND. Default is OVERWRITE_NO. If NO, any existing file will not be saved over, and save() will return false if a file already exists. If YES, any existing file will be overwritten without notice. If APPEND and a file exists, the overwrite character (see setOverwriteChar()) and a number is appended to the file. The number will be the next free integer, starting at 1. To find the final name the file is given, use getNewName().
integer
OVERWRITE_ Constant as above
setSavePath(string $path) : boolean
Must be from absolute route e,g, /var/www.... or d:\domains...
WARNING: Do not let users enter the save path. Untested, but if
this is allowable...
"../../../place_my_evil.exe"
then could be very dangerous! Even if tested and it doesn't work, it could
be using Absolute Path mode!
Also, you may need to call clearstatcache()
todo | Test for relative path breakouts |
---|---|
todo | Add parameter to call clearstatcache()? |
string
boolean
Success or failure when setting path (i.e. path exists)setUploadErrors(array $errors)
Replaces $uploaderrors array. Must have same format
todo | Remove if we can build in PHP's errors instead of copying here |
---|
array
size(string $key) : integer
todo | check return is in bytes |
---|
string
{@link setDefault()}
integer
validKey(string $key) : string
string
{@link setDefault()}
string
$defaultkey : integer
$extensions : array
$mimetypes : array
$newname : string
$overwritechar : String
$overwritemode : integer
$requirefile : \unknown
$savepath : string
This should be defined from the root of the filesystem.
$totalfiles : integer
$uploaderrors : array
todo | Can't we use the built in constants??? |
---|
OVERWRITE_APPEND : integer
OVERWRITE_NO : integer
see | \FileUploader::setOverwriteMode() |
---|---|
todo | sort methods alphabetically |