Documentation

File
in package

Pop utils file helper class

Tags
category

Pop

author

Nick Sagona, III dev@nolainteractive.com

copyright

Copyright (c) 2009-2024 NOLA Interactive, LLC. (http://www.nolainteractive.com)

license

http://www.popphp.org/license New BSD License

version
2.1.0

Table of Contents

Properties

$basename  : string|null
Basename (filename.ext)
$defaultMimeType  : string
Default mime types
$extension  : string|null
Extension (.ext)
$filename  : string|null
Filename (filename)
$mimeType  : string|null
Mime type
$mimeTypes  : array<string|int, mixed>
Mime types
$path  : string|null
Path (/some/path)
$size  : int
Size

Methods

__construct()  : mixed
Constructor
__toString()  : string
To string
exists()  : bool
Does the file exist
formatFileSize()  : string
Format file size
formatSize()  : string
Format size into human-readable string
getAllMimeTypes()  : array<string|int, mixed>
Get the all common mime types
getBasename()  : string|null
Get the basename
getContents()  : mixed
Get the file contents
getDefaultMimeType()  : string
Get the default mime type
getExtension()  : string|null
Get the extension
getFileMimeType()  : string|null
Get file's mime type
getFilename()  : string|null
Get the filename
getMimeType()  : string|null
Get the mime type
getMimeTypes()  : array<string|int, mixed>
Get common mime types
getPath()  : string|null
Get the path
getSize()  : int
Get the size
hasBasename()  : bool
Has the basename
hasExtension()  : bool
Has the extension
hasFilename()  : bool
Has the filename
hasMimeType()  : bool
Has the mime type
hasPath()  : bool
Has the path
hasSize()  : bool
Has the size
isDefaultMimeType()  : bool
Set the default mime type
setBasename()  : File
Set the basename
setDefaultMimeType()  : File
Set the mime type to default mime type
setExtension()  : File
Set the extension
setFilename()  : File
Set the filename
setMimeType()  : File
Set the mime type
setPath()  : File
Set the path
setSize()  : File
Set the size
toArray()  : array<string|int, mixed>
Convert file to an array

Properties

$basename

Basename (filename.ext)

protected string|null $basename = null

$defaultMimeType

Default mime types

protected static string $defaultMimeType = 'application/octet-stream'

$extension

Extension (.ext)

protected string|null $extension = null

$filename

Filename (filename)

protected string|null $filename = null

$mimeType

Mime type

protected string|null $mimeType = null

$mimeTypes

Mime types

protected static array<string|int, mixed> $mimeTypes = ['avi' => 'video/x-msvideo', 'bin' => 'application/octet-stream', 'bmp' => 'image/bmp', 'bz' => 'application/x-bzip', 'bz2' => 'application/x-bzip2', 'css' => 'text/css', 'csv' => 'text/csv', 'doc' => 'application/msword', 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'gz' => 'application/gzip', 'gif' => 'image/gif', 'htm' => 'text/html', 'html' => 'text/html', 'ico' => 'image/vnd.microsoft.icon', 'ics' => 'text/calendar', 'jar' => 'application/java-archive', 'jpe' => 'image/jpeg', 'jpg' => 'image/jpeg', 'jpeg' => 'image/jpeg', 'js' => 'text/javascript', 'json' => 'application/json', 'jwt' => 'application/jwt', 'log' => 'text/plain', 'mid' => 'audio/midi', 'midi' => 'audio/midi', 'mp3' => 'audio/mpeg', 'mp4' => 'video/mp4', 'mpeg' => 'video/mpeg', 'odp' => 'application/vnd.oasis.opendocument.presentation', 'ods' => 'application/vnd.oasis.opendocument.spreadsheet', 'odt' => 'application/vnd.oasis.opendocument.text', 'oga' => 'audio/ogg', 'ogv' => 'video/ogg', 'ogx' => 'application/ogg', 'otf' => 'font/otf', 'png' => 'image/png', 'pdf' => 'application/pdf', 'php' => 'application/x-httpd-php', 'ppt' => 'application/vnd.ms-powerpoint', 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation', 'psd' => 'image/vnd.adobe.photoshop', 'rar' => 'application/vnd.rar', 'rtf' => 'application/rtf', 'sgml' => 'application/sgml', 'sql' => 'application/sql', 'svg' => 'image/svg+xml', 'tar' => 'application/x-tar', 'tif' => 'image/tiff', 'tiff' => 'image/tiff', 'ttf' => 'font/ttf', 'tsv' => 'text/tsv', 'txt' => 'text/plain', 'wav' => 'audio/wav', 'xhtml' => 'application/xhtml+xml', 'xls' => 'application/vnd.ms-excel', 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'xml' => 'application/xml', 'yaml' => 'application/yaml', 'zip' => 'application/zip']

$path

Path (/some/path)

protected string|null $path = null

$size

Size

protected int $size = 0

Methods

__construct()

Constructor

public __construct([string|null $filename = null ]) : mixed

Instantiate the file object

Parameters
$filename : string|null = null

__toString()

To string

public __toString() : string
Return values
string

exists()

Does the file exist

public exists() : bool
Return values
bool

formatFileSize()

Format file size

public static formatFileSize(int $filesize[, int $round = 2 ][, bool|null $case = null ][, string $space = ' ' ]) : string
Parameters
$filesize : int
$round : int = 2
$case : bool|null = null

null = UPPER (MB); true = Title (Mb); false = lower (mb)

$space : string = ' '
Return values
string

formatSize()

Format size into human-readable string

public formatSize([int $round = 2 ][, bool|null $case = null ][, string $space = ' ' ]) : string
Parameters
$round : int = 2
$case : bool|null = null

null = UPPER (MB); true = Title (Mb); false = lower (mb)

$space : string = ' '
Return values
string

getAllMimeTypes()

Get the all common mime types

public getAllMimeTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getBasename()

Get the basename

public getBasename() : string|null
Return values
string|null

getContents()

Get the file contents

public getContents() : mixed

getDefaultMimeType()

Get the default mime type

public getDefaultMimeType() : string
Return values
string

getExtension()

Get the extension

public getExtension() : string|null
Return values
string|null

getFileMimeType()

Get file's mime type

public static getFileMimeType(string $filename) : string|null
Parameters
$filename : string
Return values
string|null

getFilename()

Get the filename

public getFilename() : string|null
Return values
string|null

getMimeType()

Get the mime type

public getMimeType() : string|null
Return values
string|null

getMimeTypes()

Get common mime types

public static getMimeTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>

getPath()

Get the path

public getPath() : string|null
Return values
string|null

getSize()

Get the size

public getSize() : int
Return values
int

hasBasename()

Has the basename

public hasBasename() : bool
Return values
bool

hasExtension()

Has the extension

public hasExtension() : bool
Return values
bool

hasFilename()

Has the filename

public hasFilename() : bool
Return values
bool

hasMimeType()

Has the mime type

public hasMimeType() : bool
Return values
bool

hasPath()

Has the path

public hasPath() : bool
Return values
bool

hasSize()

Has the size

public hasSize() : bool
Return values
bool

isDefaultMimeType()

Set the default mime type

public isDefaultMimeType() : bool
Return values
bool

setBasename()

Set the basename

public setBasename(string $basename) : File
Parameters
$basename : string
Return values
File

setDefaultMimeType()

Set the mime type to default mime type

public setDefaultMimeType() : File
Return values
File

setExtension()

Set the extension

public setExtension(string $extension) : File
Parameters
$extension : string
Return values
File

setFilename()

Set the filename

public setFilename(string $filename) : File
Parameters
$filename : string
Return values
File

setMimeType()

Set the mime type

public setMimeType(string $mimeType) : File
Parameters
$mimeType : string
Return values
File

setPath()

Set the path

public setPath(string $path) : File
Parameters
$path : string
Return values
File

setSize()

Set the size

public setSize(int $size) : File
Parameters
$size : int
Return values
File

toArray()

Convert file to an array

public toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>

        
On this page

Search results