PHP Class Contao\Files

The class handles file operations, either directly via the PHP functions or through an FTP connection. The latter is a workaround for insufficient file permissions when the PHP process runs under a different user than the file owner (referred to as "Safe Mode Hack"). Usage: $files = Files::getInstance(); $files->mkdir('test'); $files->fopen('test/one.txt', 'wb'); $files->fputs('My test'); $files->fclose(); $files->rrdir('test');
Mostra file Open project: contao/core-bundle Class Usage Examples

Protected Properties

Property Type Description
$objInstance Files Object instance (Singleton)

Public Methods

Method Description
__clone ( ) Prevent cloning of the object (Singleton)
chmod ( string $strFile, mixed $varMode ) : boolean Change the file mode
copy ( string $strSource, string $strDestination ) : boolean Copy a file or folder
delete ( string $strFile ) : boolean Delete a file
fclose ( resource $resFile ) : boolean Close a file handle
fopen ( string $strFile, string $strMode ) : resource Open a file and return the handle
fputs ( resource $resFile, string $strContent ) Write content to a file
getInstance ( ) : Files Instantiate the object (Factory)
is_writeable ( string $strFile ) : boolean Check whether a file is writeable
mkdir ( string $strDirectory ) : boolean Create a directory
move_uploaded_file ( string $strSource, string $strDestination ) : boolean Move an uploaded file to a folder
rcopy ( string $strSource, string $strDestination ) Recursively copy a directory
rename ( string $strOldName, string $strNewName ) : boolean Rename a file or folder
rmdir ( string $strDirectory ) : boolean Remove a directory
rrdir ( string $strFolder, boolean $blnPreserveRoot = false ) Recursively remove a directory

Protected Methods

Method Description
__construct ( ) Prevent direct instantiation (Singleton)
validate ( ) Validate a path

Method Details

__clone() final public method

Prevent cloning of the object (Singleton)
final public __clone ( )

__construct() protected method

Prevent direct instantiation (Singleton)
protected __construct ( )

chmod() public method

Change the file mode
public chmod ( string $strFile, mixed $varMode ) : boolean
$strFile string The file name
$varMode mixed The new file mode
return boolean True if the operation was successful

copy() public method

Copy a file or folder
public copy ( string $strSource, string $strDestination ) : boolean
$strSource string The source file or folder
$strDestination string The new file or folder path
return boolean True if the operation was successful

delete() public method

Delete a file
public delete ( string $strFile ) : boolean
$strFile string The file name
return boolean True if the operation was successful

fclose() public method

Close a file handle
public fclose ( resource $resFile ) : boolean
$resFile resource The file handle
return boolean True if the operation was successful

fopen() public method

Open a file and return the handle
public fopen ( string $strFile, string $strMode ) : resource
$strFile string The file name
$strMode string The operation mode
return resource The file handle

fputs() public method

Write content to a file
public fputs ( resource $resFile, string $strContent )
$resFile resource The file handle
$strContent string The content to store in the file

getInstance() public static method

Instantiate the object (Factory)
public static getInstance ( ) : Files
return Files The files object

is_writeable() public method

Check whether a file is writeable
public is_writeable ( string $strFile ) : boolean
$strFile string The file name
return boolean True if the file is writeable

mkdir() public method

Create a directory
public mkdir ( string $strDirectory ) : boolean
$strDirectory string The directory name
return boolean True if the operation was successful

move_uploaded_file() public method

Move an uploaded file to a folder
public move_uploaded_file ( string $strSource, string $strDestination ) : boolean
$strSource string The source file
$strDestination string The new file path
return boolean True if the operation was successful

rcopy() public method

Recursively copy a directory
public rcopy ( string $strSource, string $strDestination )
$strSource string The source file or folder
$strDestination string The new file or folder path

rename() public method

Rename a file or folder
public rename ( string $strOldName, string $strNewName ) : boolean
$strOldName string The old name
$strNewName string The new name
return boolean True if the operation was successful

rmdir() public method

Remove a directory
public rmdir ( string $strDirectory ) : boolean
$strDirectory string The directory name
return boolean True if the operation was successful

rrdir() public method

Recursively remove a directory
public rrdir ( string $strFolder, boolean $blnPreserveRoot = false )
$strFolder string The directory name
$blnPreserveRoot boolean If true, the root folder will not be removed

validate() protected method

Validate a path
protected validate ( )

Property Details

$objInstance protected_oe static_oe property

Object instance (Singleton)
protected static Files,contao $objInstance
return Files