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
- checkFilename() : bool
- Check if filename is valid and corresponds with mimetype
- 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
checkFilename()
Check if filename is valid and corresponds with mimetype
public
static checkFilename(string $filename, string $mimetype[, int $mode = 1 ]) : bool
Parameters
- $filename : string
- $mimetype : string
- $mode : int = 1
-
1=very strict
Return values
bool —false if filename is invalid
checksum()
Calculate the checksum of a file
public
static checksum(string $file) : string
This method calculates the md5 sum of the file's content.
Parameters
- $file : string
-
name of file
Return values
string —md5 sum of file
copyDir()
Copy a directory
public
static copyDir(string $sourcePath, string $targetPath) : bool
This method copies a directory recursively including all its files.
Parameters
- $sourcePath : string
-
path of directory to copy
- $targetPath : string
-
path of target directory
Return values
boolcopyFile()
Make copy of file
public
static copyFile(mixed $source, mixed $target) : bool
Parameters
- $source : mixed
-
name of file to be copied
- $target : mixed
-
name of target file
Return values
boolfile_exists()
Check if file exists
public
static file_exists(string $file) : bool
Parameters
- $file : string
-
name of file to be checked
Return values
bool —true if file exists
fileExtension()
Return file extension by mimetype
public
static fileExtension(string $mimetype) : string
This methods returns the common file extension for a given mime type.
Parameters
- $mimetype : string
Return values
string —file extension with the dot or an empty string
fileSize()
Return size of file
public
static fileSize(mixed $file) : bool|int
Parameters
- $file : mixed
-
name of file
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(string $source[, bool $level = false ]) : bool|string
Parameters
- $source : string
-
path of file to be compressed
- $level : bool = false
-
level of compression
Return values
bool|string —file name of compressed file or false in case of an error
linkFile()
Create symbolic link
public
static linkFile(mixed $source, mixed $target) : bool
Parameters
- $source : mixed
-
name of link
- $target : mixed
-
name of file to link
Return values
boolmakeDir()
Create a directory
public
static makeDir(string $path) : bool
Parameters
- $path : string
-
path of new directory
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(string $sourcePath, string $targetPath) : bool
Parameters
- $sourcePath : string
-
path of directory to be moved
- $targetPath : string
-
new name of directory
Return values
boolmoveFile()
Move file
public
static moveFile(mixed $source, mixed $target) : bool
Parameters
- $source : mixed
-
name of file to be moved
- $target : mixed
-
name of target file
Return values
boolparse_filesize()
Parses a string like '[0-9]+ *[BKMGT]*' into an integer
public
static parse_filesize(string $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
- $str : string
-
string to be parsed
Return values
bool|intremoveDir()
Delete directory
public
static removeDir(string $path) : bool
This method recursively deletes a directory including all its files.
Parameters
- $path : string
-
path of directory to be deleted
Return values
boolremoveFile()
Delete a file
public
static removeFile(mixed $file) : bool
Parameters
- $file : mixed
-
name of file
Return values
boolrenameDir()
Rename a directory
public
static renameDir(string $old, string $new) : bool
Parameters
- $old : string
-
name of directory to be renamed
- $new : string
-
new name of directory
Return values
boolrenameFile()
Rename a file
public
static renameFile(mixed $old, mixed $new) : bool
Parameters
- $old : mixed
-
old name of file
- $new : mixed
-
new name of file