Menu

## SeedDMS_Core_File
in package

inc.FileUtils.php : 29

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

category

  DMS

author

  Markus Westphal, Malcolm Cowe, Uwe Steinmann uwe@steinmann.cx

copyright

  Copyright (C) 2002-2005 Markus Westphal, 2006-2008 Malcolm Cowe, 2010 Matteo Lucarelli, 2010-2024 Uwe Steinmann

### 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()

inc.FileUtils.php : 221

Calculate the checksum of a file

`public static checksum( $file) : string`

This method calculates the md5 sum of the file's content.

##### Parameters

$file :

  name of file

##### Return values

string —

md5 sum of file

#### copyDir()

inc.FileUtils.php : 535

Copy a directory

`public static copyDir( $sourcePath, $targetPath) : bool`

This method copies a directory recursively including all its files.

##### Parameters

$sourcePath :

  path of directory to copy

$targetPath :

  path of target directory

##### Return values

bool

#### copyFile()

inc.FileUtils.php : 58

Make copy of file

`public static copyFile( $source, $target) : bool`

##### Parameters

$source :

  name of file to be copied

$target :

  name of target file

##### Return values

bool

#### file_exists()

inc.FileUtils.php : 209

Check if file exists

`public static file_exists( $file) : bool`

##### Parameters

$file :

  name of file to be checked

##### Return values

bool —

true if file exists

#### fileExtension()

inc.FileUtils.php : 233

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()

inc.FileUtils.php : 92

Return size of file

`public static fileSize( $file) : bool|int`

##### Parameters

$file :

  name of file

##### Return values

bool|int

#### format_filesize()

inc.FileUtils.php : 162

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

string

#### gzcompressfile()

inc.FileUtils.php : 578

Compress a file with gzip

`public static gzcompressfile( $source[, bool $level = false ]) : bool|string`

##### Parameters

$source :

  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()

inc.FileUtils.php : 69

Create symbolic link

`public static linkFile( $source, $target) : bool`

##### Parameters

$source :

  name of link

$target :

  name of file to link

##### Return values

bool

#### makeDir()

inc.FileUtils.php : 445

Create a directory

`public static makeDir( $path) : bool`

##### Parameters

$path :

  path of new directory

##### Return values

bool

#### mimetype()

inc.FileUtils.php : 113

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()

inc.FileUtils.php : 564

Move a directory

`public static moveDir( $sourcePath, $targetPath) : bool`

##### Parameters

$sourcePath :

  path of directory to be moved

$targetPath :

  new name of directory

##### Return values

bool

#### moveFile()

inc.FileUtils.php : 80

Move file

`public static moveFile( $source, $target) : bool`

##### Parameters

$source :

  name of file to be moved

$target :

  name of target file

##### Return values

bool

#### parse_filesize()

inc.FileUtils.php : 178

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

$str :

  string to be parsed

##### Return values

bool|int

#### removeDir()

inc.FileUtils.php : 507

Delete directory

`public static removeDir( $path) : bool`

This method recursively deletes a directory including all its files.

##### Parameters

$path :

  path of directory to be deleted

##### Return values

bool

#### removeFile()

inc.FileUtils.php : 47

Delete a file

`public static removeFile( $file) : bool`

##### Parameters

$file :

  name of file

##### Return values

bool

#### renameDir()

inc.FileUtils.php : 435

Rename a directory

`public static renameDir( $old, $new) : bool`

##### Parameters

$old :

  name of directory to be renamed

$new :

  new name of directory

##### Return values

bool

#### renameFile()

inc.FileUtils.php : 37

Rename a file

`public static renameFile( $old, $new) : bool`

##### Parameters

$old :

  old name of file

$new :

  new name of file

##### Return values

bool

## Search results