PHP Class F

Inheritance: extends E
Afficher le fichier Open project: getkirby/toolkit Class Usage Examples

Méthodes publiques

Свойство Type Description
$mimes
$types
$units

Méthodes publiques

Méthode Description
append ( string $file, mixed $content ) : boolean Appends new content to an existing file
base64 ( string $file ) : string Returns the file content as base64 encoded string
copy ( string $file, string $target ) : boolean Copy a file to a new location.
dirname ( string $file ) : string Just an alternative for dirname() to stay consistent
download ( $file, $name = null ) * Automatically sends all needed headers for the file to be downloaded and echos the file's content
exists ( string $file ) : boolean Checks if a file exists
extension ( string $file, string $extension = false ) : string Gets the extension of a file
extensionToMime ( string $extension ) : string Converts a file extension to a mime type
extensionToType ( string $extension ) : string Returns the file type for a passed extension
extensions ( string $type = null ) : array Returns all extensions for a certain file type
filename ( string $name ) : string Extracts the filename from a file path
is ( string $file, string $value ) : boolean Checks if a file is of a certain type
isReadable ( string $file ) : boolean Checks if the file is readable
isWritable ( string $file ) : boolean Checks if the file is writable
load ( $file, $data = [] ) Safely requires a file if it exists
mime ( string $file ) : mixed Returns the mime type of a file
mimeToExtension ( string $mime ) : string Converts a mime type to a file extension
mimeToType ( string $mime ) : string Returns the type for a given mime
mimes ( ) : array Returns all detectable mime types
modified ( string $file, string $format = null, string $handler = 'date' ) : integer Get the file's last modification time.
move ( string $old, string $new ) : boolean Moves a file to a new location
name ( string $name ) : string Extracts the name from a file path or filename without extension
niceSize ( mixed $size ) : string Converts an integer size into a human readable format
read ( string $file ) : mixed Reads the content of a file
remove ( string $file ) : boolean Deletes a file
resolve ( string $base, array $extensions ) : string | false Tries to find a file by various extensions
safeName ( string $string ) : string Sanitize a filename to strip unwanted special characters
show ( string $file ) Read and send the file with the correct headers
size ( mixed $file ) : mixed Returns the size of a file.
type ( string $file ) : string Categorize the file
types ( ) : array Returns an array of all available file types
unzip ( string $file, string $to ) : boolean Unzips a zip file
uri ( string $file ) : string Returns the file as data uri
write ( string $file, mixed $content, boolean $append = false ) : boolean Creates a new file

Method Details

append() public static méthode

Appends new content to an existing file
public static append ( string $file, mixed $content ) : boolean
$file string The path for the file
$content mixed Either a string or an array. Arrays will be converted to JSON.
Résultat boolean

base64() public static méthode

Returns the file content as base64 encoded string
public static base64 ( string $file ) : string
$file string The path for the file
Résultat string

copy() public static méthode

Copy a file to a new location.
public static copy ( string $file, string $target ) : boolean
$file string
$target string
Résultat boolean

dirname() public static méthode

$dirname = f::dirname('/var/www/test.txt'); dirname is /var/www
public static dirname ( string $file ) : string
$file string The path
Résultat string

download() public static méthode

* Automatically sends all needed headers for the file to be downloaded and echos the file's content
public static download ( $file, $name = null )
$file The root to the file
$name Optional filename for the download

exists() public static méthode

Checks if a file exists
public static exists ( string $file ) : boolean
$file string
Résultat boolean

extension() public static méthode

$extension = f::extension('test.txt'); extension is txt
public static extension ( string $file, string $extension = false ) : string
$file string The filename or path
$extension string Set an optional extension to overwrite the current one
Résultat string

extensionToMime() public static méthode

Converts a file extension to a mime type
public static extensionToMime ( string $extension ) : string
$extension string
Résultat string

extensionToType() public static méthode

Returns the file type for a passed extension
public static extensionToType ( string $extension ) : string
$extension string
Résultat string

extensions() public static méthode

Returns all extensions for a certain file type
public static extensions ( string $type = null ) : array
$type string
Résultat array

filename() public static méthode

$filename = f::filename('/var/www/test.txt'); filename is test.txt
public static filename ( string $name ) : string
$name string The path
Résultat string

is() public static méthode

Checks if a file is of a certain type
public static is ( string $file, string $value ) : boolean
$file string Full path to the file
$value string An extension or mime type
Résultat boolean

isReadable() public static méthode

Checks if the file is readable
public static isReadable ( string $file ) : boolean
$file string
Résultat boolean

isWritable() public static méthode

Checks if the file is writable
public static isWritable ( string $file ) : boolean
$file string
Résultat boolean

load() public static méthode

Safely requires a file if it exists
public static load ( $file, $data = [] )

mime() public static méthode

Returns the mime type of a file
public static mime ( string $file ) : mixed
$file string
Résultat mixed

mimeToExtension() public static méthode

Converts a mime type to a file extension
public static mimeToExtension ( string $mime ) : string
$mime string
Résultat string

mimeToType() public static méthode

Returns the type for a given mime
public static mimeToType ( string $mime ) : string
$mime string
Résultat string

mimes() public static méthode

Returns all detectable mime types
public static mimes ( ) : array
Résultat array

modified() public static méthode

Get the file's last modification time.
public static modified ( string $file, string $format = null, string $handler = 'date' ) : integer
$file string
$format string
$handler string date or strftime
Résultat integer

move() public static méthode

$move = f::move('test.txt', 'super.txt'); if($move) echo 'The file has been moved';
public static move ( string $old, string $new ) : boolean
$old string The current path for the file
$new string The path to the new location
Résultat boolean

name() public static méthode

$name = f::name('/var/www/test.txt'); name is test
public static name ( string $name ) : string
$name string The path or filename
Résultat string

niceSize() public static méthode

$niceSize = f::niceSize('/path/to/a/file.txt'); nice size is i.e: 212 kb $niceSize = f::niceSize(1231939); nice size is: 1,2 mb
public static niceSize ( mixed $size ) : string
$size mixed The file size or a file path
Résultat string

read() public static méthode

$content = f::read('test.txt'); i.e. content is hello $content = f::read('text.txt', 'json'); returns an array with the parsed content
public static read ( string $file ) : mixed
$file string The path for the file
Résultat mixed

remove() public static méthode

$remove = f::remove('test.txt'); if($remove) echo 'The file has been removed';
public static remove ( string $file ) : boolean
$file string The path for the file
Résultat boolean

resolve() public static méthode

Tries to find a file by various extensions
public static resolve ( string $base, array $extensions ) : string | false
$base string
$extensions array
Résultat string | false

safeName() public static méthode

$safe = f::safeName('über genious.txt'); safe will be ueber-genious.txt
public static safeName ( string $string ) : string
$string string The file name
Résultat string

show() public static méthode

Read and send the file with the correct headers
public static show ( string $file )
$file string

size() public static méthode

$size = f::size('/var/www/test.txt'); size is ie: 1231939
public static size ( mixed $file ) : mixed
$file mixed The path
Résultat mixed

type() public static méthode

Categorize the file
public static type ( string $file ) : string
$file string Either the file path or extension
Résultat string

types() public static méthode

Returns an array of all available file types
public static types ( ) : array
Résultat array

unzip() public static méthode

Unzips a zip file
public static unzip ( string $file, string $to ) : boolean
$file string
$to string
Résultat boolean

uri() public static méthode

Returns the file as data uri
public static uri ( string $file ) : string
$file string The path for the file
Résultat string

write() public static méthode

f::write('test.txt', 'hello'); creates a new text file with hello as content create a new file f::write('text.txt', array('test' => 'hello')); creates a new file and encodes the array as json
public static write ( string $file, mixed $content, boolean $append = false ) : boolean
$file string The path for the new file
$content mixed Either a string, an object or an array. Arrays and objects will be serialized.
$append boolean true: append the content to an exisiting file if available. false: overwrite.
Résultat boolean

Property Details

$mimes public_oe static_oe property

public static $mimes

$types public_oe static_oe property

public static $types

$units public_oe static_oe property

public static $units