elxisFiles

Last update by Elxis Team

Elxis file handler library

Class elxisFiles is a file manager library for Elxis. It contains all the needed tools you will need to handle files and more over has FTP backup support to automatically solve file permissions issues.

To get/create an instance of elxisFiles use the following.

$eFiles = eFactory::getFiles();

Paths

All paths provided to elxisFiles methods are relative paths from elxis root folder or from elxis repository folder. Never provide elxisFiles methods with a full absolute path. So you can access Elxis and Elxis repository files of the same level and no other files on the web site. As the Elxis repository may located in a different location regarding to Elxis root folder (for example above the www folder) all methods have an argument to declare if the given relative path is in Elxis repository or not.

Methods

Here is a list of all available public methods. Most methods return true on success and false on failure. By using the getError method you can get a detailed error message in case of failure.

chmod

public function chmod($path, $mode, $inrepo=false);
Change mode to a file or folder. Mode should be a 4 digits length octal number.

deleteFile

public function deleteFile($path, $inrepo=false);
Deletes a file.

deleteFiles

public function deleteFiles($paths=array(), $inrepo=false);
Deletes an array of files.

deleteFolder

public function deleteFolder($path, $inrepo=false);
Deletes a folder and all its containing files and folders.

copy

public function copy($src_path, $dest_path, $inrepo_src=false, $inrepo_dest=false);
Copy a file from one location to an other. If the destination container folder does not exist Elxis will try to create it.

copyFolder

public function copyFolder($src_path, $dest_path, $inrepo_src=false, $inrepo_dest=false);
Copy recursively the contents of a folder to an other folder. If the destination folder does not exist Elxis will try to create it. If the destination folder exists Elxis will not delete it but will copy the files/folders to the destination overwriting existing ones.

moveFolder

public function moveFolder($src_path, $dest_path, $inrepo_src=false, $inrepo_dest=false);
Move a file from one location to an other. If the destination container folder does not exist Elxis will try to create it.

move

public function move($src_path, $dest_path, $inrepo_src=false, $inrepo_dest=false);
Move recursively the contents of a folder to an other folder. If the destination folder does not exist Elxis will try to create it. If the destination folder exists Elxis will not delete it but will copy the files/folders to the destination overwriting existing ones. The source folder will be deleted in case of success. moveFolder will return true but an error message will be generated if the copy succeed but the deletion of the source folder fail. Use getError method to check this.

listFiles

public function listFiles($path, $filter = '.', $recurse=false, $fullpath=false, $inrepo=false);
List recursively (or not) files in a given path and optional filter the results.

listFolders

public function listFolders($path, $recurse=false, $fullpath=false, $inrepo=false);
List recursively (or not) folders in a given path.

createFile

public function createFile($path, $data=null, $inrepo=false, $forcenew=true);
Create a file and write data in it. If the last argument forcenew is true then Elxis will overwrite the existing file. Else it will append the data to the existing file (as writeFile method).

writeFile

public function writeFile($path, $data=null, $inrepo=false);
Alias of createFile but with the last argument (forcenew) always to false. So it will append the data to an existing file and never re-create it. writeFile will create the file only if it does not exist.

createFolder

public function createFolder($path, $mode=0755, $inrepo=false);
Create a folder. If needed it will create all the other container folders in order to match the path structure provided by path.

upload

public function upload($src_path, $dest_path, $inrepo=false);
Upload a file to given destination folder.
  • (string) $src_path The name of the PHP (temporary) uploaded file (usually: $userfile['tmp_name'])
  • (string) $dest_path The path (including filename) to move the uploaded file.
  • (boolean) $inrepo True if the destination folder is in Elxis repository

getExtension

public function getExtension($file);
Returns the extension of a file.

getFilename

public function getFilename($file);
Returns the file name without the extension.

getNameExtension

public function getNameExtension($file);
Returns the file name and extension as an array (having keys name and extension).

getMimetype

public function getMimetype($file);
Returns the mime type for a file. In case of error returns an empty string.

resizeImage

public function resizeImage($src_file, $width, $height, $crop=false, $inrepo=false);
Resize a jpg, jpeg, png or gif image.
  • (string) src_file The relative elxis path to the source image file.
  • (integer) width The width in pixels of the final image.
  • (integer) height The height in pixels of the final image.
  • (boolean) crop If true the final image will be croped inorder to avoid image distortion.
  • (boolean) inrepo Whether the image is located in elxis repository or not.

getError

public function getError();
Returns the generated error message of the last action. If the action completed successfully it will return an empty string.

Examples

$eFiles->chmod('modules/mod_test/sample.jpg', 0644);
Change mode to file sample.jpg to 644

$eFiles->copy('media/images/test.jpg', 'modules/mod_sample/mypic.jpg');
Copy file test.jpg to folder mod_sample renamed as mypic.jpg.

$eFiles->copyFolder('media/images/', 'backup/mypics/', true, false);
Copy folder images to repository

It has been read 5336 times
eRegistry
Previous article
eRegistry
elxisPathway
Next article
elxisPathway

You are free to copy, distribute and transmit the articles in this site for non-commercial purposes.
Creative Commons 3.0