\Disco\classesFileHelper

Helper for interacting with file system files.

Summary

Methods
Properties
Constants
humanFileSize()
iniHumanFriendlySize()
getExtension()
getMimeType()
getMimeTypeByExtension()
recursiveIterate()
emptyDir()
removeDir()
copyDir()
chmodRecursive()
serveFile()
XServeFile()
serveAsDownload()
XServeAsDownload()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
downloadHeaders()
serve()
XServe()
isFileOrDie()
$mimeCache
$copyDirBasePathLen
N/A

Properties

$mimeCache

$mimeCache : array

Type

array — MIME types cache.

$copyDirBasePathLen

$copyDirBasePathLen : 

Type

— $copyDirBasePathLen Used when copying directories recursivly to another directory.

Methods

humanFileSize()

humanFileSize(integer  $bytes, integer  $decimals = 2) : string

Format a number of bytes as human friendly text.

Parameters

integer $bytes

The number of bytes to format

integer $decimals

The number of decimal places for the returned format.

Returns

string

iniHumanFriendlySize()

iniHumanFriendlySize(string  $size) : string

Human friendly file size of a value using a convention supported in php ini values.

Parameters

string $size

The ini size.

Returns

string

getExtension()

getExtension(string  $path) : string

Get the file extension type from a path.

Parameters

string $path

The file.

Returns

string —

The extension.

getMimeType()

getMimeType(string  $file) : string

Get a file type based on the file MIME info.

Parameters

string $file

The file.

Returns

string —

The type.

getMimeTypeByExtension()

getMimeTypeByExtension(  $path) : null|string

Get a file extension type based on the file MIME info.

Parameters

$path

Returns

null|string —

The extension.

recursiveIterate()

recursiveIterate(string  $path) : array

Iterate over a diretory and all its children including other directories.

Parameters

string $path

The path of the directory to iterate through.

Returns

array

emptyDir()

emptyDir(string  $path, array  $except = array()) : boolean

Empty a directory.

Parameters

string $path

The direcotry to empty.

array $except

Dont remove paths included in this array.

Returns

boolean

removeDir()

removeDir(string  $path) : boolean

Remove a directory.

Parameters

string $path

The directory to remove.

Returns

boolean

copyDir()

copyDir(string  $path, string  $toPath, boolean  $nested = false) : boolean

Copy a directory.

Parameters

string $path

The direcotry to copy.

string $toPath

The directory to copy to.

boolean $nested

Whether to create the $path directory in $toPath or not.

Returns

boolean

chmodRecursive()

chmodRecursive(string  $path, integer  $mode) 

Change file mode for directory and all contents.

Parameters

string $path

The directory to chmod recursivly.

integer $mode

The file mode to apply.

serveFile()

serveFile(string  $path) : void

Serve a file with the proper `Content-type` header value set for use in a browser context. The content type is determined by calling `$this->getMimeTypeByExtension($path)`. If the file doesn't exist then it will serve a 404.

Parameters

string $path

The file to serve.

XServeFile()

XServeFile(string  $path) : void

Serve a file using the Apache module XSendFile `https://tn123.org/mod_xsendfile/` with the proper `Content-type` header value set for use in a browser context. The content type is determined by calling `$this->getMimeTypeByExtension($path)`. If the file doesn't exist then it will serve a 404.

Parameters

string $path

The file to serve.

serveAsDownload()

serveAsDownload(string  $path) : void

Serve a file as a download.

Parameters

string $path

The file to be downloaded.

XServeAsDownload()

XServeAsDownload(string  $path) : void

Serve a file as a download using the Apache module XSendFile.

Parameters

string $path

The file to be downloaded.

downloadHeaders()

downloadHeaders(string  $path) : void

Set the header values necessary for serving a file as a dowload.

Parameters

string $path

The file thats being downloaded.

serve()

serve(string  $path) : void

Serve a file.

Parameters

string $path

The file thats being downloaded.

XServe()

XServe(string  $path) : void

Serve a file using the Apache XSendFile module.

Parameters

string $path

The file thats being downloaded.

isFileOrDie()

isFileOrDie(string  $path) : void

If the file doesn't exist serve a 404 and exit.

Parameters

string $path

The file.