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 functionchmod($path, $mode, $inrepo=false);
Change mode to a file or folder. Mode should be a 4 digits length octal number.
deleteFile
public functiondeleteFile($path, $inrepo=false);
Deletes a file.
deleteFiles
public functiondeleteFiles($paths=array(), $inrepo=false);
Deletes an array of files.
deleteFolder
public functiondeleteFolder($path, $inrepo=false);
Deletes a folder and all its containing files and folders.
copy
public functioncopy($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 functioncopyFolder($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 functionmoveFolder($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 functionmove($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 functionlistFiles($path, $filter = '.', $recurse=false, $fullpath=false, $inrepo=false);
List recursively (or not) files in a given path and optional filter the results.
listFolders
public functionlistFolders($path, $recurse=false, $fullpath=false, $inrepo=false);
List recursively (or not) folders in a given path.
createFile
public functioncreateFile($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 functionwriteFile($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 functioncreateFolder($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 functionupload($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 functiongetExtension($file);
Returns the extension of a file.
getFilename
public functiongetFilename($file);
Returns the file name without the extension.
getNameExtension
public functiongetNameExtension($file);
Returns the file name and extension as an array (having keys name and extension).
getMimetype
public functiongetMimetype($file);
Returns the mime type for a file. In case of error returns an empty string.
resizeImage
public functionresizeImage($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 functiongetError();
Returns the generated error message of the last action. If the action completed successfully it will return an empty string.