PHP Classes


Recommend this page to a friend!
  Classes of Kushal Pogul   File Functions   Download  
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: File Functions
Manipulate local and remote files in a FTP server
Author: By
Last change:
Date: 5 years ago
Size: 3,707 bytes


Class file image Download

FTP File upload, Download, Delete & File manipulation operations plugin for CakePHP 3.X

Software License

Plugin helps to upload, download, delete file from FTP Server. This plugin also allows various useful file manipulation operations.


You can install this plugin into your CakePHP application using composer.

The recommended way to install composer packages is:

composer require kushalpogul/file-functions

After installing it you'll need to load it on your bootstrap.php file:

Plugin::load('FileFunctions', ['autoload' => true]);

And load it into initialize() function of Controller File:

$this->loadComponent('FileFunctions.File' );	


1) CakePHP 3 2) PHP 5.4 3) FTP Server

Functions in Plugin

Plugin allows upload, download, delete file from FTP Server, file manipulation operations like create, append, prepend, save content into file, last modified time, delete file, make copy of file, rename file, check file is readable and writable, change permission of file and get File Extension.


1) For FTP File Upload, Download & Delete:

In Controller file:

	//  Create Object 
	$file_obj = $this->File->getObject();       							
	// Connect to FTP using host name, username, password
	$ftp_conn=  $file_obj->ftpConnect('HOST', 'USERNAME' , 'PASSWORD');         

	// ftpFileUpload returns true -> after upload, false -> failure
	$file_obj->ftpFileUpload($ftp_conn, 'server_file', 'local_file');           

	// ftpFileDownload returns true -> after download, false -> failure
	$file_obj->ftpFileDownload($ftp_conn,'server_file', 'local_file');          

	// ftpFileDeletereturns true -> after delete, false -> failure

	// Close FTP Connection

2) For File Manipulation operation:

In Controller file:

	//  Create Object 
	$file_obj = $this->File->getObject();       

	// Set file
	// createFile returns true -> file is created, false -> file is already present

	// append returns true -> text is appended, false -> failure
	$file_obj->append('Last Text');          

	// prepend returns true -> text is prepend, false -> failure
	$file_obj->prepend('Start Text');        

	// save returns true -> content of file is replaced by text, false -> failure
	$file_obj->save('This is new Text');     

	// modified returns date & time of when file was modified last, false -> failure	
	echo $file_obj->modified();            

	// delete returns true -> file is deleted, false -> failure	

	// copyFile returns true -> file copied , false -> failure	
	// renameFile returns true -> file is renamed , false -> failure	

	// isFileReadable returns true -> file is readable, false -> file is not readable	

	// isFileWritable returns true -> file is writable, false -> file is not writable

	// changePermission returns true -> file permission is changed, false -> failure     	
	// getFileType returns file type, false -> failure	  	
	echo $file_obj->getFileType();