Detailed Description

FileUtil provides basic support for file functionality like HTTP file upload.

Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 22 of file FileUtil.php.

Static Public Member Functions

static uploadFile ($mediaFile, $destName, $mimeTypes=null, $override=true)
 
static getMimeType ($file)
 
static fputsUnicode ($fp, $str)
 
static getFiles ($directory, $pattern='/./', $prependDirectoryName=false, $recursive=false)
 
static getDirectories ($directory, $pattern='/./', $prependDirectoryName=false, $recursive=false)
 
static copyRec ($source, $dest)
 
static copyRecDir ($source, $dest)
 
static mkdirRec ($dirname, $perm=0775)
 
static emptyDir ($dirname)
 
static realpath ($path)
 
static sanitizeFilename ($file)
 
static fixFilename ($file)
 
static urlencodeFilename ($file)
 
static fileExists ($file)
 
static basename ($file)
 

Member Function Documentation

◆ uploadFile()

static uploadFile (   $mediaFile,
  $destName,
  $mimeTypes = null,
  $override = true 
)
static

Copy an uploaded file to a given destination (only if the mime type matches the given one).

Parameters
$mediaFileAn associative array with the following keys: 'name', 'type', 'tmp_name' (typically a $_FILES entry)
$destNameThe destination file name
$mimeTypesAn array holding the allowed mime types, null if arbitrary (default: null)
$overrideBoolean whether an existing file should be overridden, if false an unique id will be placed in the filename to prevent overriding (default: true)
Returns
The filename of the uploaded file

Definition at line 32 of file FileUtil.php.

◆ getMimeType()

static getMimeType (   $file)
static

Get the mime type of the given file.

Parameters
$fileThe file
Returns
String

Definition at line 66 of file FileUtil.php.

◆ fputsUnicode()

static fputsUnicode (   $fp,
  $str 
)
static

Write unicode to file.

Parameters
$fpFile Handle
$strString to write

Definition at line 86 of file FileUtil.php.

◆ getFiles()

static getFiles (   $directory,
  $pattern = '/./',
  $prependDirectoryName = false,
  $recursive = false 
)
static

Definition at line 98 of file FileUtil.php.

◆ getDirectories()

static getDirectories (   $directory,
  $pattern = '/./',
  $prependDirectoryName = false,
  $recursive = false 
)
static

Definition at line 138 of file FileUtil.php.

◆ copyRec()

static copyRec (   $source,
  $dest 
)
static

Recursive copy for files/directories.

Parameters
$sourceThe name of the source directory/file
$destThe name of the destination directory/file

Definition at line 179 of file FileUtil.php.

◆ copyRecDir()

static copyRecDir (   $source,
  $dest 
)
static

Recursive copy for directories.

Parameters
$sourceThe name of the source directory
$destThe name of the destination directory

Definition at line 196 of file FileUtil.php.

◆ mkdirRec()

static mkdirRec (   $dirname,
  $perm = 0775 
)
static

Recursive directory creation.

Parameters
$dirnameThe name of the directory
$permThe permission for the new directories (default: 0775)

Definition at line 215 of file FileUtil.php.

◆ emptyDir()

static emptyDir (   $dirname)
static

Empty a directory.

Parameters
$dirnameThe name of the directory

Definition at line 225 of file FileUtil.php.

◆ realpath()

static realpath (   $path)
static

Realpath function that also works for non existing paths code from http://www.php.net/manual/en/function.realpath.php.

Parameters
$path
Returns
String

Definition at line 244 of file FileUtil.php.

◆ sanitizeFilename()

static sanitizeFilename (   $file)
static

Get a sanitized filename code from: http://stackoverflow.com/questions/2021624/string-sanitizer-for-filename#2021729.

Parameters
$file
Returns
String

Definition at line 275 of file FileUtil.php.

◆ fixFilename()

static fixFilename (   $file)
static

Fix the name of an existing file to be used with php file functions.

Parameters
$file
Returns
String or null, if the file does not exist

Definition at line 286 of file FileUtil.php.

◆ urlencodeFilename()

static urlencodeFilename (   $file)
static

Url encode a file path.

Parameters
$file
Returns
String

Definition at line 304 of file FileUtil.php.

◆ fileExists()

static fileExists (   $file)
static

Check if the given file exists.

Parameters
$file
Returns
Boolean

Definition at line 318 of file FileUtil.php.

◆ basename()

static basename (   $file)
static

Get the trailing name component of a path (locale independent)

Parameters
$file
Returns
String

Definition at line 327 of file FileUtil.php.