Class directory_info

Description

Generic (re-usable) class to retrieve information on files / directories

Class which can retrieve information on files, sub-directories and files within sub-directories.

You can retrieve various kinds of lists with filenames as well as retrieve information about individual files, such as the file-size, file-last-access-date, file-last-modified-date and more.

The class defaults to image files only, but based on the parameters you pass, information on any type of file can be retrieved.

*********************************************************************
Features
*********************************************************************

  • Generate a filelist / directory list as an array
  • Include subdirectories / files within subdirectories ($recursion = true)
  • Create a selection within the generated filelist based on:
    * file extension(s)
    * file extension(s) + mimetype check
    * last modified date
    * last access date
  • Create a selection within an earlier made selection
  • Sort the filelist
  • Find out which is the most recently changed file + the timestamp
  • Find out the directory size of
    * a directory
    * a directory and all subdirectories within it
    * a selection of files within a directory
    * same but then including selected files in subdirectories
  • Check whether the file extension of a file is within an allowed list (defaults to image files)
  • Check whether the mime-type of a file is within an allowed list (defaults to image files)
  • Combine the above two checks
  • Get information on individual files:
    * filesize (optionally in a human readable format)
    * last modified date (optionally in a - self-defined - human readable format)
    * last access date (optionally in a - self-defined - human readable format)
    * file permissions in a human readable format
    * file owner id
    * mime-type
  • Change an arbitrary filesize to a human readable format
*********************************************************************
Basics on how to use the class
*********************************************************************

How to instantiate ?

  1. <?php
  2. $dirobj = new directory_info( );
  3. ?>

How to view the results ?
You can format the results display yourself, to quickly retrieve and view a filelist, you can use:

  1. <?php
  2. // Get a filelist for $pathtodir, $recursion = true,
  3. // don't use a previously made selection (null)
  4. $dirobj->get_filelist( null, $pathtodir, true );
  5. print 'filecount is : ' . $dirobj->filecount;
  6. print '<pre>';
  7. print_r( $dirobj->filelist );
  8. print '</pre>';
  9. ?>

Note: The directory path passed to a methods should be relative to the location of the calling file and should end with a trailing slash

  1. <?php
  2. $pathtodir = 'images/';
  3. ?>

For more extended examples of how to use this class, have a look at the example file which came with this class. It should be located in /example/example.php

*********************************************************************
Version management information
*********************************************************************

  • v1.5 2006-09-02
    - Improved inline documentation to work with phpDocumentor and updated the example file
    - Created separate methods to set the class variables and moved the main filelist get functionality out of the class instantiation
    - Created various methods for retrieving selections of a filelist - Adjusted the methods to auto-re-use or auto-destroy the previous retrieved results so you can keep re-using the (instantiated) class
    - Made a lot of file related methods static, i.e. callable without instantiating the class
    - Added lots of new methods
  • v1.4 2006-07-04
    - Added filecount variable
  • v1.3 2005-12-24
    - Added support for uppercase filenames and uppercase extensions passed
  • v1.2 2005-12-05
    - Rewrite of function to class to improve re-usability
    - Added filesize option
  • v1.0 2004-07-15
    - Originally posted as a function to the comments section of http://www.php.net/function.readdir
*********************************************************************

Located in /directoryinfo.inc.php (line 125)


	
			
Variable Summary
Method Summary
bool check_allowed_file (string $pathtofile, [array|string $exts = null], [bool $strict = null], [array $mimetypes = null])
bool check_file_extension (string $filename, [array|string $exts = null])
bool check_file_mimetype (string $pathtofile, [array $mimetypes = null])
int get_dirsize ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
array get_dir_list (string $pathtodir, [bool $recursive = null])
array get_ext_based_filelist ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null], [array|string $exts = null], [bool $strict = null], [array $mimetypes = null])
array get_filelist ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
int|false get_filesize (string $pathtofile)
array get_files_accessed_before (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
array get_files_accessed_since (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
array get_files_modified_before (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
array get_files_modified_since (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
int|false get_file_owner (string $pathtofile)
string get_human_readable_dirsize ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
string|false get_human_readable_filesize (string $pathtofile)
string|false get_human_readable_file_permissions (string $pathtofile)
string|false get_human_readable_lastacc (string $pathtofile, [string $datetime_format = null])
string|false get_human_readable_lastmod (string $pathtofile, [string $datetime_format = null])
int|false get_lastacc_unixts (string $pathtofile)
int|false get_lastmod_unixts (string $pathtofile)
string|false get_mime_content_type (string $pathtofile)
array get_most_recent_file ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
array get_sorted_dirlist ([bool $sort_asc = null], [string $pathtodir = null], [bool $recursive = null])
array get_sorted_filelist ([bool $sort_asc = null], [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
string|false human_readable_filesize (int $filesize)
bool set_datetime_format (string $datetime_format)
bool set_default_exts (array|string $exts)
bool set_default_mimetypes (array $mimetypes)
bool set_default_path (string $pathtodir)
bool set_safe_exts (bool $safe_exts)
bool set_strict (bool $strict)
bool valid_pathtofile (string $pathtofile)
Variables
string $datetime_format = 'Y-m-d H:i:s' (line 216)

Default format string for the human readable last modified and last access date

int $dircount = 0 (line 289)

Directory count result variable

Count of number of directories in $dirlist

array $dirlist = array() (line 265)

Directory result array

array|string $exts = array( 'jpg', 'gif', 'jpeg', 'png' ) (line 168)

Array of file extensions

The list is used to determine which files should be included in the result array if you want to make a selection based on file extensions

  • Should be an array of file extensions to show only files which comply with these extensions
  • Alternatively, the special string-value all will show files independent of extensions.
  • Defaults to typical image file extensions (jpg, gif, jpeg, png)

int $filecount = 0 (line 273)

File count result variable

Count of number of files in $filelist

array $filelist = array() (line 251)

Filelist result array

array $filelist_selection = array() (line 258)

Filelist selection result array

int $fileselection_count = 0 (line 281)

File count of selection result variable

Count of number of files in $filelist_selection

array|string $last_exts (line 323)

Remember last validated extensions for efficiency

array $last_mimetypes (line 339)

Remember last validated mimetypes for efficiency

array|string $last_passed_exts (line 315)

Remember last passed extensions for efficiency

array $last_passed_mimetypes (line 331)

Remember last passed mimetypes for efficiency

string $last_path (line 298)

Remember last path traversed for efficiency

string $last_recursive (line 307)

Remember last recursive setting for efficiency

  • Default for recursion is false

array $mimetypes = array( 'image/jpeg', 'image/png', 'image/gif' ) (line 188)

Array of mime types

The list is used to determine which files should be included in the result array if you want to strictly check that the files returned not only comply with the file extensions given, but are also of the expected mimetype.

  • Should be an array of mimetypes to show only files which comply with these mimetypes
  • High level mimetypes (content-types such as image) may be used and will be converted to an array which covers all mimetypes within that content-type.
  • If left empty and a strict check is done via the check_allowed_file() method, the relevant mimetypes will be guessed based on the passed extensions.
  • Defaults to typical image file extensions (jpg, gif, jpeg, png)

array $mime_map = array(
'ai' => 'application/postscript',
'aif' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'asc' => 'text/plain',
'au' => 'audio/basic',
'avi' => 'video/x-msvideo',
'bcpio' => 'application/x-bcpio',
'bin' => 'application/octet-stream',
'c' => 'text/plain',
'cc' => 'text/plain',
'ccad' => 'application/clariscad',
'cdf' => 'application/x-netcdf',
'class' => 'application/octet-stream',
'cpio' => 'application/x-cpio',
'cpt' => 'application/mac-compactpro',
'csh' => 'application/x-csh',
'css' => 'text/css',
'dcr' => 'application/x-director',
'dir' => 'application/x-director',
'dms' => 'application/octet-stream',
'doc' => 'application/msword',
'drw' => 'application/drafting',
'dvi' => 'application/x-dvi',
'dwg' => 'application/acad',
'dxf' => 'application/dxf',
'dxr' => 'application/x-director',
'eps' => 'application/postscript',
'etx' => 'text/x-setext',
'exe' => 'application/octet-stream',
'ez' => 'application/andrew-inset',
'f' => 'text/plain',
'f90' => 'text/plain',
'fli' => 'video/x-fli',
'gif' => 'image/gif',
'gtar' => 'application/x-gtar',
'gz' => 'application/x-gzip',
'h' => 'text/plain',
'hdf' => 'application/x-hdf',
'hh' => 'text/plain',
'hqx' => 'application/mac-binhex40',
'htm' => 'text/html',
'html' => 'text/html',
'ice' => 'x-conference/x-cooltalk',
'ief' => 'image/ief',
'iges' => 'model/iges',
'igs' => 'model/iges',
'ips' => 'application/x-ipscript',
'ipx' => 'application/x-ipix',
'jpe' => 'image/jpeg',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'js' => 'application/x-javascript',
'kar' => 'audio/midi',
'latex' => 'application/x-latex',
'lha' => 'application/octet-stream',
'lsp' => 'application/x-lisp',
'lzh' => 'application/octet-stream',
'm' => 'text/plain',
'man' => 'application/x-troff-man',
'me' => 'application/x-troff-me',
'mesh' => 'model/mesh',
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'mif' => 'application/vnd.mif',
'mime' => 'www/mime',
'mov' => 'video/quicktime',
'movie' => 'video/x-sgi-movie',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'mpe' => 'video/mpeg',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpga' => 'audio/mpeg',
'ms' => 'application/x-troff-ms',
'msh' => 'model/mesh',
'nc' => 'application/x-netcdf',
'oda' => 'application/oda',
'pbm' => 'image/x-portable-bitmap',
'pdb' => 'chemical/x-pdb',
'pdf' => 'application/pdf',
'pgm' => 'image/x-portable-graymap',
'pgn' => 'application/x-chess-pgn',
'php' => 'text/plain',
'php3' => 'text/plain',
'png' => 'image/png',
'pnm' => 'image/x-portable-anymap',
'pot' => 'application/mspowerpoint',
'ppm' => 'image/x-portable-pixmap',
'pps' => 'application/mspowerpoint',
'ppt' => 'application/mspowerpoint',
'ppz' => 'application/mspowerpoint',
'pre' => 'application/x-freelance',
'prt' => 'application/pro_eng',
'ps' => 'application/postscript',
'qt' => 'video/quicktime',
'ra' => 'audio/x-realaudio',
'ram' => 'audio/x-pn-realaudio',
'ras' => 'image/cmu-raster',
'rgb' => 'image/x-rgb',
'rm' => 'audio/x-pn-realaudio',
'roff' => 'application/x-troff',
'rpm' => 'audio/x-pn-realaudio-plugin',
'rtf' => 'text/rtf',
'rtx' => 'text/richtext',
'scm' => 'application/x-lotusscreencam',
'set' => 'application/set',
'sgm' => 'text/sgml',
'sgml' => 'text/sgml',
'sh' => 'application/x-sh',
'shar' => 'application/x-shar',
'silo' => 'model/mesh',
'sit' => 'application/x-stuffit',
'skd' => 'application/x-koan',
'skm' => 'application/x-koan',
'skp' => 'application/x-koan',
'skt' => 'application/x-koan',
'smi' => 'application/smil',
'smil' => 'application/smil',
'snd' => 'audio/basic',
'sol' => 'application/solids',
'spl' => 'application/x-futuresplash',
'src' => 'application/x-wais-source',
'step' => 'application/STEP',
'stl' => 'application/SLA',
'stp' => 'application/STEP',
'sv4cpio' => 'application/x-sv4cpio',
'sv4crc' => 'application/x-sv4crc',
'swf' => 'application/x-shockwave-flash',
't' => 'application/x-troff',
'tar' => 'application/x-tar',
'tcl' => 'application/x-tcl',
'tex' => 'application/x-tex',
'texi' => 'application/x-texinfo',
'texinfo' => 'application/x-texinfo',
'tif' => 'image/tiff',
'tiff' => 'image/tiff',
'tr' => 'application/x-troff',
'tsi' => 'audio/TSP-audio',
'tsp' => 'application/dsptype',
'tsv' => 'text/tab-separated-values',
'txt' => 'text/plain',
'unv' => 'application/i-deas',
'ustar' => 'application/x-ustar',
'vcd' => 'application/x-cdlink',
'vda' => 'application/vda',
'viv' => 'video/vnd.vivo',
'vivo' => 'video/vnd.vivo',
'vrml' => 'model/vrml',
'wav' => 'audio/x-wav',
'wrl' => 'model/vrml',
'xbm' => 'image/x-xbitmap',
'xlc' => 'application/vnd.ms-excel',
'xll' => 'application/vnd.ms-excel',
'xlm' => 'application/vnd.ms-excel',
'xls' => 'application/vnd.ms-excel',
'xlw' => 'application/vnd.ms-excel',
'xml' => 'text/xml',
'xpm' => 'image/x-xpixmap',
'xwd' => 'image/x-xwindowdump',
'xyz' => 'chemical/x-pdb',
'zip' => 'application/zip'
)
(line 1520)

Mapping of file extensions to their expected mime-type

This mapping does not claim to be exhaustive, but is a good listing for a large amount of file types.

Last updated: 2006-08-31

string $pathtodir = './' (line 140)

Directory to traverse

  • Relative path to a directory, i.e. relative to the calling file
  • IMPORTANT: end the path with a trailing '/' !!!
  • Defaults to the current directory

bool $safe_exts = true (line 152)

Only show 'safe' files/directories ?

  • true means: only show 'safe' files (not .htaccess or references to higher directories)
  • false means: show all files
  • Defaults to true

boolean $strict = false (line 201)

Do a strict file type check ?

Whether to check whether the files with the correct extension *really* are of the mime-type you would expect for a file with that extension.

  • Defaults to false, i.e. don't do a strict check

array $valid_mime_types = array(
'application' => array( 'activemessage', 'andrew-inset', 'applefile', 'atom+xml',
'atomicmail', 'batch-SMTP', 'beep+xml', 'cals-1840', 'ccxml+xml', 'cnrp+xml',
'commonground', 'conference-info+xml', 'cpl+xml', 'csta+xml', 'CSTAdata+xml',
'cybercash', 'dca-rft', 'dec-dx', 'dialog-info+xml', 'dicom', 'dns', 'dvcs',
'ecmascript', 'EDI-Consent', 'EDIFACT', 'EDI-X12', 'epp+xml', 'eshop', 'example',
'fastinfoset', 'fastsoap', 'fits', 'font-tdpfr', 'H224', 'http', 'hyperstudio',
'iges', 'im-iscomposing+xml', 'index', 'index.cmd', 'index.obj', 'index.response',
'index.vnd', 'iotp', 'ipp', 'isup', 'javascript', 'json', 'kpml-request+xml',
'kpml-response+xml', 'mac-binhex40', 'macwriteii', 'marc', 'mathematica', 'mbox',
'mikey', 'mpeg4-generic', 'mpeg4-iod', 'mpeg4-iod-xmt', 'mp4', 'msword', 'mxf',
'nasdata', 'news-message-id', 'news-transmission', 'nss', 'ocsp-request',
'ocsp-response', 'octet-stream', 'oda', 'ogg', 'parityfec', 'pdf', 'pgp-encrypted',
'pgp-keys', 'pgp-signature', 'pidf+xml', 'pkcs10', 'pkcs7-mime', 'pkcs7-signature',
'pkix-cert', 'pkixcmp', 'pkix-crl', 'pkix-pkipath', 'pls+xml', 'poc-settings+xml',
'postscript', 'prs.alvestrand.titrax-sheet', 'prs.cww', 'prs.nprend', 'prs.plucker',
'rdf+xml', 'qsig', 'reginfo+xml', 'relax-ng-compact-syntax', 'remote-printing',
'resource-lists+xml', 'riscos', 'rlmi+xml', 'rls-services+xml', 'rtf', 'rtx',
'samlassertion+xml', 'samlmetadata+xml', 'sbml+xml', 'sdp', 'set-payment',
'set-payment-initiation', 'set-registration', 'set-registration-initiation',
'sgml', 'sgml-open-catalog', 'shf+xml', 'sieve', 'simple-filter+xml',
'simple-message-summary', 'slate', 'smil', //OBSOLETE
'smil+xml', 'soap+fastinfoset', 'soap+xml', 'spirits-event+xml', 'srgs',
'srgs+xml', 'ssml+xml', 'timestamp-query', 'timestamp-reply', 'tve-trigger', 'vemmi',
'vnd.3gpp.bsf+xml', 'vnd.3gpp.pic-bw-large', 'vnd.3gpp.pic-bw-small',
'vnd.3gpp.pic-bw-var', 'vnd.3gpp.sms', 'vnd.3gpp2.bcmcsinfo+xml', 'vnd.3gpp2.sms',
'vnd.3M.Post-it-Notes', 'vnd.accpac.simply.aso', 'vnd.accpac.simply.imp',
'vnd.acucobol', 'vnd.acucorp', 'vnd.adobe.xfdf', 'vnd.aether.imp', 'vnd.amiga.ami',
'vnd.anser-web-certificate-issue-initiation', 'vnd.apple.installer+xml',
'vnd.audiograph', 'vnd.autopackage', 'vnd.blueice.multipass', 'vnd.bmi',
'vnd.businessobjects', 'vnd.canon-cpdl', 'vnd.canon-lips', 'vnd.cinderella',
'vnd.chipnuts.karaoke-mmd', 'vnd.claymore', 'vnd.commerce-battelle',
'vnd.commonspace', 'vnd.cosmocaller', 'vnd.contact.cmsg', 'vnd.crick.clicker',
'vnd.crick.clicker.keyboard', 'vnd.crick.clicker.palette',
'vnd.crick.clicker.template', 'vnd.crick.clicker.wordbank',
'vnd.criticaltools.wbs+xml', 'vnd.ctc-posml', 'vnd.cups-pdf', 'vnd.cups-postscript',
'vnd.cups-ppd', 'vnd.cups-raster', 'vnd.cups-raw', 'vnd.curl', 'vnd.cybank',
'vnd.data-vision.rdz', 'vnd.dna', 'vnd.dpgraph', 'vnd.dreamfactory',
'vnd.dvb.esgcontainer', 'vnd.dvb.ipdcesgaccess', 'vnd.dxr', 'vnd.ecdis-update',
'vnd.ecowin.chart', 'vnd.ecowin.filerequest', 'vnd.ecowin.fileupdate',
'vnd.ecowin.series', 'vnd.ecowin.seriesrequest', 'vnd.ecowin.seriesupdate',
'vnd.enliven', 'vnd.epson.esf', 'vnd.epson.msf', 'vnd.epson.quickanime',
'vnd.epson.salt', 'vnd.epson.ssf', 'vnd.ericsson.quickcall', 'vnd.eudora.data',
'vnd.ezpix-album', 'vnd.ezpix-package', 'vnd.fdf', 'vnd.ffsns', 'vnd.fints',
'vnd.FloGraphIt', 'vnd.fluxtime.clip', 'vnd.framemaker', 'vnd.frogans.fnc',
'vnd.frogans.ltf', 'vnd.fsc.weblaunch', 'vnd.fujitsu.oasys', 'vnd.fujitsu.oasys2',
'vnd.fujitsu.oasys3', 'vnd.fujitsu.oasysgp', 'vnd.fujitsu.oasysprs',
'vnd.fujixerox.ART4', 'vnd.fujixerox.ART-EX', 'vnd.fujixerox.ddd',
'vnd.fujixerox.docuworks', 'vnd.fujixerox.docuworks.binder', 'vnd.fujixerox.HBPL',
'vnd.fut-misnet', 'vnd.genomatix.tuxedo', 'vnd.grafeq', 'vnd.groove-account',
'vnd.groove-help', 'vnd.groove-identity-message', 'vnd.groove-injector',
'vnd.groove-tool-message', 'vnd.groove-tool-template', 'vnd.groove-vcard',
'vnd.HandHeld-Entertainment+xml', 'vnd.hbci', 'vnd.hcl-bireports',
'vnd.hhe.lesson-player', 'vnd.hp-HPGL', 'vnd.hp-hpid', 'vnd.hp-hps',
'vnd.hp-jlyt', 'vnd.hp-PCL', 'vnd.hp-PCLXL', 'vnd.httphone', 'vnd.hzn-3d-crossword',
'vnd.ibm.afplinedata', 'vnd.ibm.electronic-media', 'vnd.ibm.MiniPay',
'vnd.ibm.modcap', 'vnd.ibm.rights-management', 'vnd.ibm.secure-container',
'vnd.igloader', 'vnd.informix-visionary', 'vnd.intercon.formnet',
'vnd.intertrust.digibox', 'vnd.intertrust.nncp', 'vnd.intu.qbo', 'vnd.intu.qfx',
'vnd.ipunplugged.rcprofile', 'vnd.irepository.package+xml', 'vnd.is-xpr',
'vnd.japannet-directory-service', 'vnd.japannet-jpnstore-wakeup',
'vnd.japannet-payment-wakeup', 'vnd.japannet-registration',
'vnd.japannet-registration-wakeup', 'vnd.japannet-setstore-wakeup',
'vnd.japannet-verification', 'vnd.japannet-verification-wakeup',
'vnd.jisp', 'vnd.kahootz', 'vnd.kde.karbon', 'vnd.kde.kchart', 'vnd.kde.kformula',
'vnd.kde.kivio', 'vnd.kde.kontour', 'vnd.kde.kpresenter', 'vnd.kde.kspread',
'vnd.kde.kword', 'vnd.kenameaapp', 'vnd.kidspiration', 'vnd.Kinar',
'vnd.koan', 'vnd.liberty-request+xml', 'vnd.llamagraphics.life-balance.desktop',
'vnd.llamagraphics.life-balance.exchange+xml', 'vnd.lotus-1-2-3',
'vnd.lotus-approach', 'vnd.lotus-freelance', 'vnd.lotus-notes',
'vnd.lotus-organizer', 'vnd.lotus-screencam', 'vnd.lotus-wordpro',
'vnd.marlin.drm.mdcf', 'vnd.mcd', 'vnd.medcalcdata', 'vnd.mediastation.cdkey',
'vnd.meridian-slingshot', 'vnd.mfmp', 'vnd.micrografx.flo', 'vnd.micrografx.igx',
'vnd.mif', 'vnd.minisoft-hp3000-save', 'vnd.mitsubishi.misty-guard.trustweb',
'vnd.Mobius.DAF', 'vnd.Mobius.DIS', 'vnd.Mobius.MBK', 'vnd.Mobius.MQY',
'vnd.Mobius.MSL', 'vnd.Mobius.PLC', 'vnd.Mobius.TXF', 'vnd.mophun.application',
'vnd.mophun.certificate', 'vnd.motorola.flexsuite', 'vnd.motorola.flexsuite.adsi',
'vnd.motorola.flexsuite.fis', 'vnd.motorola.flexsuite.gotap',
'vnd.motorola.flexsuite.kmr', 'vnd.motorola.flexsuite.ttc',
'vnd.motorola.flexsuite.wem', 'vnd.mozilla.xul+xml', 'vnd.ms-artgalry',
'vnd.ms-asf', 'vnd.ms-cab-compressed', 'vnd.mseq', 'vnd.ms-excel',
'vnd.ms-fontobject', 'vnd.ms-htmlhelp', 'vnd.msign', 'vnd.ms-ims', 'vnd.ms-lrm',
'vnd.ms-powerpoint', 'vnd.ms-project', 'vnd.ms-tnef', 'vnd.ms-wmdrm.lic-chlg-req',
'vnd.ms-wmdrm.lic-resp', 'vnd.ms-works', 'vnd.ms-wpl', 'vnd.ms-xpsdocument',
'vnd.musician', 'vnd.music-niff', 'vnd.nervana', 'vnd.netfpx',
'vnd.noblenet-directory', 'vnd.noblenet-sealer', 'vnd.noblenet-web',
'vnd.nokia.catalogs', 'vnd.nokia.conml+wbxml', 'vnd.nokia.conml+xml',
'vnd.nokia.iptv.config+xml', 'vnd.nokia.landmark+wbxml', 'vnd.nokia.landmark+xml',
'vnd.nokia.landmarkcollection+xml', 'vnd.nokia.pcd+wbxml', 'vnd.nokia.pcd+xml',
'vnd.nokia.radio-preset', 'vnd.nokia.radio-presets', 'vnd.novadigm.EDM',
'vnd.novadigm.EDX', 'vnd.novadigm.EXT', 'vnd.oasis.opendocument.chart',
'vnd.oasis.opendocument.chart-template', 'vnd.oasis.opendocument.formula',
'vnd.oasis.opendocument.formula-template', 'vnd.oasis.opendocument.graphics',
'vnd.oasis.opendocument.graphics-template', 'vnd.oasis.opendocument.image',
'vnd.oasis.opendocument.image-template', 'vnd.oasis.opendocument.presentation',
'vnd.oasis.opendocument.presentation-template', 'vnd.oasis.opendocument.spreadsheet',
'vnd.oasis.opendocument.spreadsheet-template', 'vnd.oasis.opendocument.text',
'vnd.oasis.opendocument.text-master', 'vnd.oasis.opendocument.text-template',
'vnd.oasis.opendocument.text-web', 'vnd.obn', 'vnd.oma.dd2+xml',
'vnd.omads-email+xml', 'vnd.omads-file+xml', 'vnd.omads-folder+xml',
'vnd.omaloc-supl-init', 'vnd.osa.netdeploy', 'vnd.osgi.dp', 'vnd.otps.ct-kip+xml',
'vnd.palm', 'vnd.paos.xml', 'vnd.pg.format', 'vnd.pg.osasli',
'vnd.piaccess.application-licence', 'vnd.picsel', 'vnd.pocketlearn',
'vnd.powerbuilder6', 'vnd.powerbuilder6-s', 'vnd.powerbuilder7',
'vnd.powerbuilder75', 'vnd.powerbuilder75-s', 'vnd.powerbuilder7-s',
'vnd.preminet', 'vnd.previewsystems.box', 'vnd.proteus.magazine',
'vnd.publishare-delta-tree', 'vnd.pvi.ptid1', 'vnd.pwg-multiplexed',
'vnd.pwg-xhtml-print+xml', 'vnd.qualcomm.brew-app-res', 'vnd.Quark.QuarkXPress',
'vnd.rapid', 'vnd.RenLearn.rlprint', 'vnd.ruckus.download', 'vnd.s3sms',
'vnd.scribus', 'vnd.sealed.3df', 'vnd.sealed.csf', 'vnd.sealed.doc',
'vnd.sealed.eml', 'vnd.sealed.mht', 'vnd.sealed.net', 'vnd.sealed.ppt',
'vnd.sealed.tiff', 'vnd.sealed.xls', 'vnd.sealedmedia.softseal.html',
'vnd.sealedmedia.softseal.pdf', 'vnd.seemail', 'vnd.sema',
'vnd.shana.informed.formdata', 'vnd.shana.informed.formtemplate',
'vnd.shana.informed.interchange', 'vnd.shana.informed.package',
'vnd.smaf', 'vnd.solent.sdkm+xml', 'vnd.sss-cod', 'vnd.sss-dtf', 'vnd.sss-ntf',
'vnd.street-stream', 'vnd.sun.wadl+xml', 'vnd.sus-calendar', 'vnd.svd',
'vnd.swiftview-ics', 'vnd.syncml.dm+wbxml', 'vnd.syncml.ds.notification',
'vnd.syncml.+xml', 'vnd.triscape.mxs', 'vnd.trueapp', 'vnd.truedoc',
'vnd.ufdl', 'vnd.uiq.theme', 'vnd.umajin', 'vnd.uoml+xml', 'vnd.uplanet.alert',
'vnd.uplanet.alert-wbxml', 'vnd.uplanet.bearer-choice',
'vnd.uplanet.bearer-choice-wbxml', 'vnd.uplanet.cacheop', 'vnd.uplanet.cacheop-wbxml',
'vnd.uplanet.channel', 'vnd.uplanet.channel-wbxml', 'vnd.uplanet.list',
'vnd.uplanet.listcmd', 'vnd.uplanet.listcmd-wbxml', 'vnd.uplanet.list-wbxml',
'vnd.uplanet.signal', 'vnd.vcx', 'vnd.vectorworks', 'vnd.vd-study',
'vnd.vidsoft.vidconference', 'vnd.visio', 'vnd.visionary',
'vnd.vividence.scriptfile', 'vnd.vsf', 'vnd.wap.sic', 'vnd.wap.slc', 'vnd.wap.wbxml',
'vnd.wap.wmlc', 'vnd.wap.wmlscriptc', 'vnd.webturbo', 'vnd.wfa.wsc',
'vnd.wordperfect', 'vnd.wqd', 'vnd.wrq-hp3000-labelled', 'vnd.wt.stf',
'vnd.wv.csp+xml', 'vnd.wv.csp+wbxml', 'vnd.wv.ssp+xml', 'vnd.xara', 'vnd.xfdl',
'vnd.yamaha.hv-dic', 'vnd.yamaha.hv-script', 'vnd.yamaha.hv-voice',
'vnd.yamaha.smaf-audio', 'vnd.yamaha.smaf-phrase', 'vnd.yellowriver-custom-menu',
'vnd.zzazz.deck+xml', 'voicexml+xml', 'watcherinfo+xml', 'whoispp-query',
'whoispp-response', 'wita', 'wordperfect5.1', 'x400-bp', 'xcap-att+xml',
'xcap-caps+xml', 'xcap-el+xml', 'xcap-error+xml', 'xenc+xml',
'xhtml-voice+xml', // OBSOLETE
'xhtml+xml', 'xml', 'xml-dtd', 'xml-external-parsed-entity', 'xmpp+xml',
'xop+xml', 'xv+xml', 'zip',
),'audio'=>array('32kadpcm','3gpp','3gpp2','ac3','AMR','AMR-WB','amr-wb+','asc','basic','BV16','BV32','clearmode','CN','DAT12','dls','dsr-es201108','dsr-es202050','dsr-es202211','dsr-es202212','eac3','DVI4','EVRC','EVRC0','EVRC-QCP','example','G722','G7221','G723','G726-16','G726-24','G726-32','G726-40','G728','G729','G729D','G729E','GSM','GSM-EFR','iLBC','L8','L16','L20','L24','LPC','MPA','mp4','MP4A-LATM','mpa-robust','mpeg','mpeg4-generic','parityfec','PCMA','PCMU','prs.sid','QCELP','RED','rtp-midi','rtx','SMV','SMV0','SMV-QCP','t140c','t38','telephone-event','tone','VDVI','VMR-WB','vnd.3gpp.iufp','vnd.4SB','vnd.audiokoz','vnd.CELP','vnd.cisco.nse','vnd.cmles.radio-events','vnd.cns.anp1','vnd.cns.inf1','vnd.digital-winds','vnd.dlna.adts','vnd.everad.plj','vnd.hns.audio','vnd.lucent.voice','vnd.nokia.mobile-xmf','vnd.nortel.vbk','vnd.nuera.ecelp4800','vnd.nuera.ecelp7470','vnd.nuera.ecelp9600','vnd.octel.sbc','vnd.qcelp',// DEPRECATED - Please use audio/qcelp
'vnd.rhetorex.32kadpcm','vnd.sealedmedia.softseal.mpeg','vnd.vmx.cvsd'),'example'=>array(),'image '=>array('cgm','example','fits','g3fax','gif','ief','jp2','jpeg','jpm','jpx','naplps','png','prs.btif','prs.pti','t38','tiff','tiff-fx','vnd.adobe.photoshop','vnd.cns.inf2','vnd.djvu','vnd.dwg','vnd.dxf','vnd.fastbidsheet','vnd.fpx','vnd.fst','vnd.fujixerox.edmics-mmr','vnd.fujixerox.edmics-rlc','vnd.globalgraphics.pgb','vnd.microsoft.icon','vnd.mix','vnd.ms-modi','vnd.net-fpx','vnd.sealed.png','vnd.sealedmedia.softseal.gif','vnd.sealedmedia.softseal.jpg','vnd.svf','vnd.wap.wbmp','vnd.xiff'),'message'=>array('CPIM','delivery-status','disposition-notification','example','external-body','http','news','partial','rfc822','s-http','sip','sipfrag','tracking-status'),'model'=>array('example','iges','mesh','vnd.dwf','vnd.flatland.3dml','vnd.gdl','vnd.gs-gdl','vnd.gtw','vnd.moml+xml','vnd.mts','vnd.parasolid.transmit.binary','vnd.parasolid.transmit.text','vnd.vtu','vrml'),'multipart'=>array('alternative','appledouble','byteranges','digest','encrypted','example','form-data','header-set','mixed','parallel','related','report','signed','voice-message'),'text'=>array('calendar','css','csv','directory','dns','ecmascript',// OBSOLETE
'enriched','example','html','javascript',// OBSOLETE
'parityfec','plain','prs.fallenstein.rst','prs.lines.tag','RED','rfc822-headers','richtext','rtf','rtx','sgml','t140','tab-separated-values','troff','uri-list','vnd.abc','vnd.curl','vnd.DMClientScript','vnd.esmertec.theme-descriptor','vnd.fly','vnd.fmi.flexstor','vnd.in3d.3dml','vnd.in3d.spot','vnd.IPTC.NewsML','vnd.IPTC.NITF','vnd.latex-z','vnd.motorola.reflex','vnd.ms-mediapackage','vnd.net2phone.commcenter.command','vnd.sun.j2me.app-descriptor','vnd.wap.si','vnd.wap.sl','vnd.wap.wml','vnd.wap.wmlscript','xml','xml-external-parsed-entity'),'video'=>array('3gpp','3gpp2','3gpp-tt','BMPEG','BT656','CelB','DV','example','H261','H263','H263-1998','H263-2000','H264','JPEG','MJ2','MP1S','MP2P','MP2T','mp4','MP4V-ES','MPV','mpeg','mpeg4-generic','nv','parityfec','pointer','quicktime','raw','rtx','SMPTE292M','vc1','vnd.dlna.mpeg-tts','vnd.fvt','vnd.hns.video','vnd.motorola.video','vnd.motorola.videop','vnd.mpegurl','vnd.nokia.interleaved-multimedia','vnd.objectvideo','vnd.sealed.mpeg1','vnd.sealed.mpeg4','vnd.sealed.swf','vnd.sealedmedia.softseal.mov','vnd.vivo'))
(line 1692)

Valid mime types

Last updated on 2006-08-31

Methods
check_allowed_file (line 621)

Check whether the file is allowed based on extension and if $strict=true also on mimetype

  • Will use the class defaults for optional parameters which were not passed
  • Will try to 'guess' the mimetypes if a strict check is requested, but no mimetypes were passed
  • Returns true is the file passes, false if not.

bool check_allowed_file (string $pathtofile, [array|string $exts = null], [bool $strict = null], [array $mimetypes = null])
  • string $pathtofile: path to the file to check
  • array|string $exts: [optional] allowed extensions
  • bool $strict: [optional] whether or not to check on mimetype
  • array $mimetypes: [optional] allowed mimetypes
check_file_extension (line 679)

Check the file extension of a filename against the list of allowed extensions

  • This is a case-insensitive extension check
  • Will use the class defaults for optional parameters which were not passed
  • Returns true if the filename passes the valid extension check
  • Returns false is it fails or if the passed filename parameter is not a string

bool check_file_extension (string $filename, [array|string $exts = null])
  • string $filename: filename to check
  • array|string $exts: [optional] array of allowed extensions
check_file_mimetype (line 721)

Check the file-mimetype against a list of allowed mimetypes

  • Will use the class defaults for optional parameters which were not passed
  • Returns true if the file-mimetype is within the list of allowed mimetypes
  • Returns false if not or if the passed filename parameter is not a string

bool check_file_mimetype (string $pathtofile, [array $mimetypes = null])
  • string $pathtofile
  • array $mimetypes: [optional] array of valid mimetypes
get_dirsize (line 1478)

Get the total size of all files in $pathtodir

int get_dirsize ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • bool $use_selection: [optional] whether or not the last made selection should be used if available
  • string $pathtodir: [optional] path to the directory for which to get the size
  • bool $recursive: [optional] whether to include filesize of files in subdirectories
get_dir_list (line 1032)

Get a list of directories in $pathtodir

array get_dir_list (string $pathtodir, [bool $recursive = null])
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on directories in subdirectories
get_ext_based_filelist (line 1182)

Retrieve a filelist which only contains files which comply with the allowed extension/mimetypes

  • Creates a selection list of files which comply with the criteria set by allowed extensions / allowed mimetypes
  • $strict determined whether or not to check on mimetype
  • $exts, $strict and $mimetypes default to the class defaults if not passed

array get_ext_based_filelist ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null], [array|string $exts = null], [bool $strict = null], [array $mimetypes = null])
  • bool $use_selection: [optional] whether or not the last made selection should be returned if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
  • array|string $exts: [optional] allowed extensions
  • bool $strict: [optional] whether or not to check on mimetype
  • array $mimetypes: [optional] allowed mimetypes
get_filelist (line 998)

Get list of files in $pathtodir

  • Use this method to retrieve a filelist for a certain directory path
  • If a filelist was created before and you want to retrieve this list, you can use this function without any parameters and it will return the previously created list
  • If you created a selection based on the earlier created filelist, you can choose to retrieve that selection instead by setting $use_selection to true
  • If no filelist was created before and no parameters are passed, it will retrieve a filelist based on the class defaults
  • If you call this method as a static method, logically you can not retrieve an earlier created listing or selection list

array get_filelist ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • bool $use_selection: [optional] whether or not the last made selection should be returned if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
get_filesize (line 740)

Get the filesize of a file

int|false get_filesize (string $pathtofile)
  • string $pathtofile
get_files_accessed_before (line 1445)

Retrieve a filelist which only contains files accessed before the passed unix timestamp

  • Creates a selection list of files which comply with the criteria set by $comparets
Inspired by a comment from Benan Tumkaya (benantumkaya at yahoo) - 14-Aug-2006 11:11

array get_files_accessed_before (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • int $compare_ts: Unix timestamp for date/time to compare against
  • bool $use_selection: [optional] whether or not the last made selection should be used if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
get_files_accessed_since (line 1407)

Retrieve a filelist which only contains files accessed since the passed unix timestamp

  • Creates a selection list of files which comply with the criteria set by $comparets
Inspired by a comment from Benan Tumkaya (benantumkaya at yahoo) - 14-Aug-2006 11:11

array get_files_accessed_since (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • int $compare_ts: Unix timestamp for date/time to compare against
  • bool $use_selection: [optional] whether or not the last made selection should be used if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
get_files_modified_before (line 1369)

Retrieve a filelist which only contains files modified before the passed unix timestamp

  • Creates a selection list of files which comply with the criteria set by $comparets
Inspired by a comment from Benan Tumkaya (benantumkaya at yahoo) - 14-Aug-2006 11:11

array get_files_modified_before (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • int $compare_ts: Unix timestamp for date/time to compare against
  • bool $use_selection: [optional] whether or not the last made selection should be used if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
get_files_modified_since (line 1331)

Retrieve a filelist which only contains files modified since the passed unix timestamp

  • Creates a selection list of files which comply with the criteria set by $comparets
Inspired by a comment from Benan Tumkaya (benantumkaya at yahoo) - 14-Aug-2006 11:11

array get_files_modified_since (int $compare_ts, [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • int $compare_ts: Unix timestamp for date/time to compare against
  • bool $use_selection: [optional] whether or not the last made selection should be used if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
get_file_owner (line 878)

Get the file owner for a file

int|false get_file_owner (string $pathtofile)
  • string $pathtofile
get_human_readable_dirsize (line 1504)

Get the total size of all files in a directory in a human readable format

string get_human_readable_dirsize ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • bool $use_selection: [optional] whether or not the last made selection should be used if available
  • string $pathtodir: [optional] path to the directory for which to get the size
  • bool $recursive: [optional] whether to include filesize of files in subdirectories
get_human_readable_filesize (line 756)

Get the filesize of a file in a human readable format

string|false get_human_readable_filesize (string $pathtofile)
  • string $pathtofile
get_human_readable_file_permissions (line 917)

Get a human readable file permission string for a file

string|false get_human_readable_file_permissions (string $pathtofile)
  • string $pathtofile
get_human_readable_lastacc (line 861)

Get the last access timestamp of a file in a human readable format

string|false get_human_readable_lastacc (string $pathtofile, [string $datetime_format = null])
  • string $pathtofile
  • string $datetime_format: [optional]
get_human_readable_lastmod (line 827)

Get the last modified timestamp of a file in a human readable format

string|false get_human_readable_lastmod (string $pathtofile, [string $datetime_format = null])
  • string $pathtofile
  • string $datetime_format: [optional]
get_lastacc_unixts (line 844)

Get the last access unix timestamp for a file

int|false get_lastacc_unixts (string $pathtofile)
  • string $pathtofile
get_lastmod_unixts (line 810)

Get the last modified unix timestamp for a file

int|false get_lastmod_unixts (string $pathtofile)
  • string $pathtofile
get_mime_content_type (line 895)

Get the mime content type of a file

string|false get_mime_content_type (string $pathtofile)
  • string $pathtofile
get_most_recent_file (line 1288)

Retrieve the filename and last_modified date of the most recently modified file

Inspired by a comment from wookie at at no-way dot org - 14-Sep-2003 11:17

array get_most_recent_file ([bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • bool $use_selection: [optional] whether or not the last made selection should be used if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
get_sorted_dirlist (line 1255)

Retrieve a sorted (sub-)directory list

  • Mainly useful for reverse sorting as the normal dirlist is already sorted in ascending order
  • Defaults to ascending sort order
  • To sort descendingly, set $sort_asc to false
  • The list sorting will always use case-insensitive natural sort order
  • Retrieving a sorted list will not affect the order of the class 'remembered' dirlist

array get_sorted_dirlist ([bool $sort_asc = null], [string $pathtodir = null], [bool $recursive = null])
  • bool $sort_asc: [optional] set to false for reverse / descending sorted list
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on directories in subdirectories
get_sorted_filelist (line 1221)

Retrieve a sorted filelist

  • Mainly useful for reverse sorting as the normal filelist is already sorted in ascending order
  • Defaults to ascending sort order
  • To sort descendingly, set $sort_asc to false
  • The list sorting will always use case-insensitive natural sort order
  • Retrieving a sorted list will not affect the order of the class 'remembered' filelists

array get_sorted_filelist ([bool $sort_asc = null], [bool $use_selection = null], [string $pathtodir = null], [bool $recursive = null])
  • bool $sort_asc: [optional] set to false for reverse / descending sorted list
  • bool $use_selection: [optional] whether or not the last made selection should be returned if available
  • string $pathtodir: [optional] path to the directory for which to get the list
  • bool $recursive: [optional] whether to retrieve information on files in subdirectories
human_readable_filesize (line 778)

Creates a human readable file size string

  • Rounds bytes and kilobytes to the nearest integer
  • Rounds anything else to one digit behind the decimal point
  • Returns false is the passed parameter is not an integer or a numeric string
Examples:
the integer 1080 becomes the string 1 kB
the integer 3000000 becomes the string 2.8 MB

string|false human_readable_filesize (int $filesize)
  • int $filesize: filesize in bytes
set_datetime_format (line 443)

Change the $datetime_format default

  • Refer to $datetime_format for information on valid formats for the variable
  • Returns boolean true / false to indicate whether the default was changed succesfully

bool set_datetime_format (string $datetime_format)
  • string $datetime_format
set_default_exts (line 389)

Change the $exts default

  • Refer to $exts for information on valid formats for the variable
  • Returns boolean true / false to indicate whether the default was changed succesfully

bool set_default_exts (array|string $exts)
  • array|string $exts
set_default_mimetypes (line 408)

Change the $mimetypes default

  • Refer to $mimetypes for information on valid formats for the variable
  • Returns boolean true / false to indicate whether the default was changed succesfully

bool set_default_mimetypes (array $mimetypes)
  • array $mimetypes
set_default_path (line 355)

Change the $pathtodir default

  • Refer to $pathtodir for information on valid formats for the variable
  • Returns boolean true / false to indicate whether the default was changed succesfully

bool set_default_path (string $pathtodir)
  • string $pathtodir
set_safe_exts (line 372)

Change the $safe_exts default

  • Refer to $safe_exts for information on valid formats for the variable
  • Returns boolean true / false to indicate whether the default was changed succesfully

bool set_safe_exts (bool $safe_exts)
  • bool $safe_exts
set_strict (line 426)

Change the $strict default

  • Refer to $strict for information on valid formats for the variable
  • Returns boolean true / false to indicate whether the default was changed succesfully

bool set_strict (bool $strict)
  • bool $strict
valid_pathtofile (line 587)

Clears the file stat cache and checks whether the passed $pathtofile is a valid path to a file

bool valid_pathtofile (string $pathtofile)
  • string $pathtofile

Documentation generated on Sat, 02 Sep 2006 09:15:19 +0200 by phpDocumentor 1.3.0RC3