PHP Класс F

Наследование: extends E
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$mimes
$types
$units

Открытые методы

Метод Описание
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

Описание методов

append() публичный статический метод

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.
Результат boolean

base64() публичный статический метод

Returns the file content as base64 encoded string
public static base64 ( string $file ) : string
$file string The path for the file
Результат string

copy() публичный статический метод

Copy a file to a new location.
public static copy ( string $file, string $target ) : boolean
$file string
$target string
Результат boolean

dirname() публичный статический метод

$dirname = f::dirname('/var/www/test.txt'); dirname is /var/www
public static dirname ( string $file ) : string
$file string The path
Результат string

download() публичный статический метод

* 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() публичный статический метод

Checks if a file exists
public static exists ( string $file ) : boolean
$file string
Результат boolean

extension() публичный статический метод

$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
Результат string

extensionToMime() публичный статический метод

Converts a file extension to a mime type
public static extensionToMime ( string $extension ) : string
$extension string
Результат string

extensionToType() публичный статический метод

Returns the file type for a passed extension
public static extensionToType ( string $extension ) : string
$extension string
Результат string

extensions() публичный статический метод

Returns all extensions for a certain file type
public static extensions ( string $type = null ) : array
$type string
Результат array

filename() публичный статический метод

$filename = f::filename('/var/www/test.txt'); filename is test.txt
public static filename ( string $name ) : string
$name string The path
Результат string

is() публичный статический метод

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
Результат boolean

isReadable() публичный статический метод

Checks if the file is readable
public static isReadable ( string $file ) : boolean
$file string
Результат boolean

isWritable() публичный статический метод

Checks if the file is writable
public static isWritable ( string $file ) : boolean
$file string
Результат boolean

load() публичный статический метод

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

mime() публичный статический метод

Returns the mime type of a file
public static mime ( string $file ) : mixed
$file string
Результат mixed

mimeToExtension() публичный статический метод

Converts a mime type to a file extension
public static mimeToExtension ( string $mime ) : string
$mime string
Результат string

mimeToType() публичный статический метод

Returns the type for a given mime
public static mimeToType ( string $mime ) : string
$mime string
Результат string

mimes() публичный статический метод

Returns all detectable mime types
public static mimes ( ) : array
Результат array

modified() публичный статический метод

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
Результат integer

move() публичный статический метод

$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
Результат boolean

name() публичный статический метод

$name = f::name('/var/www/test.txt'); name is test
public static name ( string $name ) : string
$name string The path or filename
Результат string

niceSize() публичный статический метод

$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
Результат string

read() публичный статический метод

$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
Результат mixed

remove() публичный статический метод

$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
Результат boolean

resolve() публичный статический метод

Tries to find a file by various extensions
public static resolve ( string $base, array $extensions ) : string | false
$base string
$extensions array
Результат string | false

safeName() публичный статический метод

$safe = f::safeName('über genious.txt'); safe will be ueber-genious.txt
public static safeName ( string $string ) : string
$string string The file name
Результат string

show() публичный статический метод

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

size() публичный статический метод

$size = f::size('/var/www/test.txt'); size is ie: 1231939
public static size ( mixed $file ) : mixed
$file mixed The path
Результат mixed

type() публичный статический метод

Categorize the file
public static type ( string $file ) : string
$file string Either the file path or extension
Результат string

types() публичный статический метод

Returns an array of all available file types
public static types ( ) : array
Результат array

unzip() публичный статический метод

Unzips a zip file
public static unzip ( string $file, string $to ) : boolean
$file string
$to string
Результат boolean

uri() публичный статический метод

Returns the file as data uri
public static uri ( string $file ) : string
$file string The path for the file
Результат string

write() публичный статический метод

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.
Результат boolean

Описание свойств

$mimes публичное статическое свойство

public static $mimes

$types публичное статическое свойство

public static $types

$units публичное статическое свойство

public static $units