SeedDMS_Core_File
in package
Class with file operations in the document management system
Use the methods of this class only for files below the content directory but not for temporäry files, cache files or log files.
Tags
Table of Contents
Methods
- checksum() : string
- Calculate the checksum of a file
- copyDir() : bool
- Copy a directory
- copyFile() : bool
- Make copy of file
- file_exists() : bool
- Check if file exists
- fileExtension() : string
- Return file extension by mimetype
- fileSize() : bool|int
- Return size of file
- format_filesize() : string
- Turn an integer into a string with units for bytes
- gzcompressfile() : bool|string
- Compress a file with gzip
- linkFile() : bool
- Create symbolic link
- makeDir() : bool
- Create a directory
- mimetype() : string
- Return the mimetype of a given file
- moveDir() : bool
- Move a directory
- moveFile() : bool
- Move file
- parse_filesize() : bool|int
- Parses a string like '[0-9]+ *[BKMGT]*' into an integer
- removeDir() : bool
- Delete directory
- removeFile() : bool
- Delete a file
- renameDir() : bool
- Rename a directory
- renameFile() : bool
- Rename a file
Methods
checksum()
Calculate the checksum of a file
public
static checksum( $file) : string
This method calculates the md5 sum of the file's content.
Parameters
Return values
string —md5 sum of file
copyDir()
Copy a directory
public
static copyDir( $sourcePath, $targetPath) : bool
This method copies a directory recursively including all its files.
Parameters
Return values
boolcopyFile()
Make copy of file
public
static copyFile( $source, $target) : bool
Parameters
Return values
boolfile_exists()
Check if file exists
public
static file_exists( $file) : bool
Parameters
Return values
bool —true if file exists
fileExtension()
Return file extension by mimetype
public
static fileExtension(mixed $mimetype) : string
This methods returns the common file extension for a given mime type.
Parameters
- $mimetype : mixed
Return values
string —file extension with the dot or an empty string
fileSize()
Return size of file
public
static fileSize( $file) : bool|int
Parameters
Return values
bool|intformat_filesize()
Turn an integer into a string with units for bytes
public
static format_filesize(int $size[, array<string|int, mixed> $sizes = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB') ]) : string
Parameters
- $size : int
- $sizes : array<string|int, mixed> = array('Bytes', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB')
-
list of units for 10^0, 10^3, 10^6, ..., 10^(n*3) bytes
Return values
stringgzcompressfile()
Compress a file with gzip
public
static gzcompressfile( $source[, bool $level = false ]) : bool|string
Parameters
Return values
bool|string —file name of compressed file or false in case of an error
linkFile()
Create symbolic link
public
static linkFile( $source, $target) : bool
Parameters
Return values
boolmakeDir()
Create a directory
public
static makeDir( $path) : bool
Parameters
Return values
boolmimetype()
Return the mimetype of a given file
public
static mimetype(string $filename) : string
This method uses finfo to determine the mimetype but will correct some mimetypes which are not propperly determined or could be more specific, e.g. text/plain when it is actually text/markdown. In thoses cases the file extension will be taken into account.
Parameters
- $filename : string
-
name of file on disc
Return values
string —mimetype
moveDir()
Move a directory
public
static moveDir( $sourcePath, $targetPath) : bool
Parameters
Return values
boolmoveFile()
Move file
public
static moveFile( $source, $target) : bool
Parameters
Return values
boolparse_filesize()
Parses a string like '[0-9]+ *[BKMGT]*' into an integer
public
static parse_filesize( $str) : bool|int
B,K,M,G,T stand for byte, kilo byte, mega byte, giga byte, tera byte If the last character is omitted, bytes are assumed. Arbitrary spaces between the number and the unit are allowed.
Parameters
Return values
bool|intremoveDir()
Delete directory
public
static removeDir( $path) : bool
This method recursively deletes a directory including all its files.
Parameters
Return values
boolremoveFile()
Delete a file
public
static removeFile( $file) : bool
Parameters
Return values
boolrenameDir()
Rename a directory
public
static renameDir( $old, $new) : bool
Parameters
Return values
boolrenameFile()
Rename a file
public
static renameFile( $old, $new) : bool