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');
Afficher le fichier Open project: contao/core-bundle Class Usage Examples

Protected Properties

Свойство Type Description
$objInstance Files Object instance (Singleton)

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode Description
__construct ( ) Prevent direct instantiation (Singleton)
validate ( ) Validate a path

Method Details

__clone() final public méthode

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

__construct() protected méthode

Prevent direct instantiation (Singleton)
protected __construct ( )

chmod() public méthode

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

copy() public méthode

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
Résultat boolean True if the operation was successful

delete() public méthode

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

fclose() public méthode

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

fopen() public méthode

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

fputs() public méthode

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 méthode

Instantiate the object (Factory)
public static getInstance ( ) : Files
Résultat Files The files object

is_writeable() public méthode

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

mkdir() public méthode

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

move_uploaded_file() public méthode

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
Résultat boolean True if the operation was successful

rcopy() public méthode

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 méthode

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

rmdir() public méthode

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

rrdir() public méthode

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 méthode

Validate a path
protected validate ( )

Property Details

$objInstance protected_oe static_oe property

Object instance (Singleton)
protected static Files,contao $objInstance
Résultat Files