Back to the module list

File management

The file module allow the same functions as PHP file section, but allow to chroot the commands in a jail, event if the possibilty is not offered by the system.

Each command test if the user have the right to execute any parent directory and generate an exception if the user don't have the right to do an action on the filesystem.

The class definition

Class Domframework\File

Namespace Domframework

Description

/**
 The file method allow to manage files like PHP with a working chroot on all
 plateforms, and a right management compatible with database
 Don't follow links !

 To allow an external authorization test in plus of the filesystem check, you
 must extends the class and overload checkExternalPathRO and
 checkExternalPathRW.

Properties

public $debug=0;
/**
 Activate the debug and define the minimum priority to save

Methods

public function chdir ( $directory)
/**
 Change the current working directory
 @param string $directory Go in the provided directory
 @return bool true if the directory is changed
 @throws If directory not exists, or the directory is not executable

public function checkExternalPathRO ( $path)
/**
 External function allowed to be overloaded to test the RO access to a
 resource
 @param string $path The path to test in the filesystem
 @return boolean true if RO access, false if not

public function checkExternalPathRW ( $path)
/**
 External function allowed to be overloaded to test the RW access to a
 resource
 @param string $path The path to test in the filesystem
 @return boolean true if RW access, false if not

public function chgrp ( $filename, $group)
/**
 Change the group for a file/dir...
 @param string $filename The file/directory to change
 @param mixed $group The group name or group GID
 @throws If filename not exists, or the directory is not RW

public function chmod ( $filename, $mode)
/**
 Change the rights mode for a file/dir...
 @param string $filename The file/directory to change
 @param integer $mode The mode to use for the filename
 @throws If filename not exists, or the directory is not RW

public function chown ( $filename, $user)
/**
 Change the owner for a file/dir...
 @param string $filename The file/directory to change
 @param mixed $user The user name or user UID
 @throws If filename not exists, or the directory is not RW

public function chroot ( $directory)
/**
 Chroot in the provided directory
 @param string $directory The directory to chroot
 @return boolean true if the chroot is done, false if there is a failure
 @throws If directory not exists, or the directory is not executable

public function copy ( $oldname, $newname)
/**
 Copy a file or a directory
 @param string $oldname The file to copy
 @param string $newname The new name of the file. It will be
 overwrited if it already exists
 @return bool

public function fileArray ( $filename)
/**
 Get the file contents in an array (like 'file' function, but can not
 have the same name as the class...)
 @param string $filename Name of the file to read
 @return string Content of the file
 @throws If parent directory not exists, is not readable, the file is not
         exists or is not readable

public function file_exists ( $filename)
/**
 Checks whether a file or directory exists
 @param string $filename The file or directory to verify
 @return bool true if the file exists, false otherwise
 @throws If parent directory not exists, or is not executable

public function file_get_contents ( $filename)
/**
 Get the file contents
 @param string $filename Name of the file to read
 @return string Content of the file
 @throws If parent directory not exists, is not readable, the file is not
         exists or is not readable

public function file_put_contents ( $filename, $data, $flags=0)
/**
 Write a string to a file
 @param string $filename Path to the file where to write the data
 @param string|integer $data The data to write
 @param integer|null $flags The optional flags
 @return integer the length of the data stored
 @throws If parent directory not exists, is not writeable, or the file
         exists and is not writeable

public function fileinfoMimeType ( $filename)
/**
 Get the file info of the provided filename
 @param string $filename Path to the file
 @return string the mimetype of the file
 @throws If parent directory not exists, is not writeable

public function filemtime ( $filename)
/**
 Get the file modification time of a file
 @param string $filename Path to the file
 @return integer|boolean the time the file was last modified, or FALSE
 on failure. The time is returned as a Unix timestamp, which is suitable
 for the date() function.
 @throws If parent directory not exists, is not writeable

public function filesize ( $filename)
/**
 Get the file size
 @param string $filename Path to the file
 @return integer|boolean the size of the file or FALSE on failure.
 @throws If parent directory not exists, is not writeable

public function getcwd ()
/**
 Return the current working directory
 @return string the current working directory

public function glob ( $pattern, $flags=0)
/**
 Find pathnames matching a pattern
 If there is some unreadable files, skip them quietly
 @param string $pattern The pattern to found
 @param integer|null $flags The additional flags
 @return array Return an array if there is an error
 @throws If parent directory not exists, or is not executable
 or if there is one file unreadable

public function is_dir ( $filename)
/**
  Tells whether the given filename is a directory
 @param string $filename The filename to test
 @return bool true if the $filename is a directory and exists, false
              otherwise
 @throws If parent directory not exists, or is not executable

public function is_executable ( $filename)
/**
 Tells whether a file exists and is executable
 @param string $filename The filename to test
 @return bool true if the $filename is a file exists and is writeable
 @throws If parent directory not exists, or is not executable

public function is_file ( $filename)
/**
  Tells whether the given filename is a valid file
 @param string $filename The filename to test
 @return bool true if the $filename is a file and exists, false otherwise
 @throws If parent directory not exists, or is not executable

public function is_readable ( $filename)
/**
 Tells whether a file exists and is readable
 @param string $filename The filename to test
 @return bool true if the $filename is a file exists and is readable
 @throws If parent directory not exists, or is not executable

public function is_writeable ( $filename)
/**
 Tells whether a file exists and is writeable
 @param string $filename The filename to test
 @return bool true if the $filename is a file exists and is writeable
 @throws If parent directory not exists, or is not executable

public function lockEX ( $filename)
/**
 Lock a file exclusively
 @param string $filename The file to lock
 @return bool true if the lock is acquired, false otherwise
 @throws If parent directory not exists, or is not writeable

public function lockSH ( $filename)
/**
 Lock a file shared (allow multiple read)
 @param string $filename The file to lock
 @return bool true if the lock is acquired, false otherwise
 @throws If parent directory not exists, or is not writeable

public function lockUN ( $filename)
/**
 Unlock a file previously locked
 @param string $filename The file to lock
 @return bool true if the lock is acquired, false otherwise
 @throws If parent directory not exists, or is not writeable

public function md5_file ( $filename)
/**
 Calculate the md5 sum of a file
 @param string $filename The file to hash
 @return string the calulated hash
 @throws If the file doesn't exists

public function mkdir ( $pathname, $mode=511, $recursive=false)
/**
 Create a new directory
 @param string $pathname The directory to create
 @param integer $mode The mode to create (0777 by default)
 @param boolean $recursive (false by default)
 @return bool true if the directory is correctely created, false if the
              directory already exists
 @throws If parent directory not exists, is not writeable

public function parse_ini_file ( $filename, $process_sections=false)
/**
 Return a ini file converted to an array
 @param string $filename The filename of the ini file being parsed.
 @param boolean $process_sections Process the sections
 @return array

public function realpath ( $path)
/**
 Return the canonical absolute path. Do not check if the directory exists,
 if there is links. Just calculate the realpath based on the chroot value
 @param string $path the path to analyze
 @return string the canonical absolute path

public function rename ( $oldname, $newname)
/**
 Renames a file or directory
 @param string $oldname The file or directory to rename
 @param string $newname The new name of the file or directory. It will be
 overwrited if it already exists
 @return bool

public function rmdir ( $dirname, $recursive=false)
/**
 Remove the provided directory
 If the recurse flag is true, remove the content too (files and
 directories)
 @param string $dirname The directory to remove
 @param boolean $recursive Remove recursively
 @return bool true if all is removed, false otherwise
 @throws If parent directory not exists, is not writeable or the current
         dir is not writeable

public function scandir ( $directory)
/**
 Return the list of files and directories in the directory.
 Do not return the . and .. virtual dirs.
 The result is sorted
 @param string $directory The directory to read
 @return array the list of files and dirs
 @throws If directory not exists, or is not executable

public function scandirNotSorted ( $directory)
/**
 Return the list of files and directories in the directory.
 Do not return the . and .. virtual dirs.
 The result is NOT sorted
 @param string $directory The directory to read
 @return array the list of files and dirs
 @throws If directory not exists, or is not executable

public function sha1_file ( $filename)
/**
 Calculate the sha1 sum of a file
 @param string $filename The file to hash
 @return string the calulated hash
 @throws If the file doesn't exists

public function touch ( $filename, $time=null, $atime=null)
/**
 Create a new file or update the timestamp if the file exists
 @param string $filename the filename
 @param integer|null $time the timestamp to use (actual timestamp if not
 defined)
 @param integer|null $atime the access timestamp to use (actual timestamp
 if not defined)
 @return bool true or false on failure
 @throws If parent directory not exists, is not writeable

public function unlink ( $filename)
/**
 Delete an existing file.
 @param string $filename The filename to remove
 @return bool true if the file si removed, false otherwise
 @throws If parent directory not exists, or is not executable