file
in package
Table of Contents
Properties
- $MIME : mixed
Methods
- getExtension() : string
- Get the extension from filename
- getInexistantFilename() : string
- Get inexistant filename based on the given filename. If you skip $dir parameter the directory will be fetched from $filename and returned value will be full filename path. The third parameter is optional and defines the template, the filename will be renamed to. Default template is {name}({sufix}){ext}. Examples:
- getMimeType() : string
- Get MIME type of the given filename. If Fileinfo PHP extension is available the MIME type will be fetched by the file's content. The second parameter is optional and defines the magic file path. If you skip it, the default one will be loaded.
- isWritable() : bool
- Checks if the given file is really writable. The standard PHP function is_writable() does not work properly on Windows servers.
- normalizeFilename() : string
- Normalize given filename. Accented characters becomes non-accented and removes any other special characters. Usable for non-unicode filesystems
Properties
$MIME
public
static mixed
$MIME
= array('ai' => 'application/postscript', 'aif' => 'audio/x-aiff', 'aifc' => 'audio/x-aiff', 'aiff' => 'audio/x-aiff', 'avi' => 'video/x-msvideo', 'bin' => 'application/macbinary', 'bmp' => 'image/bmp', 'cpt' => 'application/mac-compactpro', 'css' => 'text/css', 'csv' => 'text/x-comma-separated-values', 'dcr' => 'application/x-director', 'dir' => 'application/x-director', 'doc' => 'application/msword', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'dvi' => 'application/x-dvi', 'dxr' => 'application/x-director', 'eml' => 'message/rfc822', 'eps' => 'application/postscript', 'flv' => 'video/x-flv', 'gif' => 'image/gif', 'gtar' => 'application/x-gtar', 'gz' => 'application/x-gzip', 'hqx' => 'application/mac-binhex40', 'htm' => 'text/html', 'html' => 'text/html', 'jpe' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'js' => 'application/x-javascript', 'log' => 'text/plain', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mif' => 'application/vnd.mif', 'mov' => 'video/quicktime', 'movie' => 'video/x-sgi-movie', 'mp2' => 'audio/mpeg', 'mp3' => 'audio/mpeg', 'mp4' => 'video/mpeg', 'mpe' => 'video/mpeg', 'mpeg' => 'video/mpeg', 'mpg' => 'video/mpeg', 'mpga' => 'audio/mpeg', 'oda' => 'application/oda', 'pdf' => 'application/pdf', 'php' => 'application/x-httpd-php', 'php3' => 'application/x-httpd-php', 'php4' => 'application/x-httpd-php', 'phps' => 'application/x-httpd-php-source', 'phtml' => 'application/x-httpd-php', 'png' => 'image/png', 'ppt' => 'application/powerpoint', 'ps' => 'application/postscript', 'psd' => 'application/x-photoshop', 'qt' => 'video/quicktime', 'ra' => 'audio/x-realaudio', 'ram' => 'audio/x-pn-realaudio', 'rm' => 'audio/x-pn-realaudio', 'rpm' => 'audio/x-pn-realaudio-plugin', 'rtf' => 'text/rtf', 'rtx' => 'text/richtext', 'rv' => 'video/vnd.rn-realvideo', 'shtml' => 'text/html', 'sit' => 'application/x-stuffit', 'smi' => 'application/smil', 'smil' => 'application/smil', 'swf' => 'application/x-shockwave-flash', 'tar' => 'application/x-tar', 'tgz' => 'application/x-tar', 'text' => 'text/plain', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'txt' => 'text/plain', 'wav' => 'audio/x-wav', 'wbxml' => 'application/wbxml', 'wmlc' => 'application/wmlc', 'word' => 'application/msword', 'xht' => 'application/xhtml+xml', 'xhtml' => 'application/xhtml+xml', 'xl' => 'application/excel', 'xls' => 'application/excel', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xml' => 'text/xml', 'xsl' => 'text/xml', 'zip' => 'application/x-zip')
Methods
getExtension()
Get the extension from filename
public
static getExtension(string $filename[, bool $toLower = true ]) : string
Parameters
- $filename : string
- $toLower : bool = true
Return values
stringgetInexistantFilename()
Get inexistant filename based on the given filename. If you skip $dir parameter the directory will be fetched from $filename and returned value will be full filename path. The third parameter is optional and defines the template, the filename will be renamed to. Default template is {name}({sufix}){ext}. Examples:
public
static getInexistantFilename(string $filename[, string $dir = null ][, string $tpl = null ]) : string
file::getInexistantFilename("/my/directory/myfile.txt"); If myfile.txt does not exist - returns the same path to the file otherwise returns "/my/directory/myfile(1).txt"
file::getInexistantFilename("myfile.txt", "/my/directory"); returns "myfile.txt" or "myfile(1).txt" or "myfile(2).txt" etc...
file::getInexistantFilename("myfile.txt", "/dir", "{name}[{sufix}]{ext}"); returns "myfile.txt" or "myfile[1].txt" or "myfile[2].txt" etc...
Parameters
- $filename : string
- $dir : string = null
- $tpl : string = null
Return values
stringgetMimeType()
Get MIME type of the given filename. If Fileinfo PHP extension is available the MIME type will be fetched by the file's content. The second parameter is optional and defines the magic file path. If you skip it, the default one will be loaded.
public
static getMimeType(string $filename[, string $magic = null ]) : string
If Fileinfo PHP extension is not available the MIME type will be fetched by filename extension regarding $MIME property. If the file extension does not exist there, returned type will be application/octet-stream
Parameters
- $filename : string
- $magic : string = null
Return values
stringisWritable()
Checks if the given file is really writable. The standard PHP function is_writable() does not work properly on Windows servers.
public
static isWritable(string $filename) : bool
Parameters
- $filename : string
Return values
boolnormalizeFilename()
Normalize given filename. Accented characters becomes non-accented and removes any other special characters. Usable for non-unicode filesystems
public
static normalizeFilename( $filename) : string