Uploading file via FTP using CodeIgniter

We are going to discuss how to upload files to the remote server in CodeIgniter using CI’s FTP library. This library has limitations – SFTP and SSL FTP protocols are not supported, only standard FTP.

CodeIgniter’s FTP Class permits files to be transferred to a remote server. Remote files can also be moved, renamed, and deleted. The FTP class also includes a “mirroring” function that permits an entire local directory to be recreated remotely via FTP.

Uploading file via FTP using CodeIgniter

Let’s start the tutorial, first, we will upload the file to the same server using CodeIgniter’s upload library, then we are going to transfer the file to the remote server using CodeIgniter’s FTP library.

Create upload directory in the local server to store uploaded files or images, we are going to mention this directory name in the CI’s upload library configuration.

Create destination directory in the remote server to store uploaded files or images, we are going to mention this directory name while configuring the CI’s FTP library.

Controller:
Create a controller file called Upload.php inside the application/controllers/ directory. Define a index() function and load the HTML view( upload form ).

Once upload form is submitted, we will upload the file to the local server and after that, we are connecting to the remote server via FTP and uploading files to the remote server from the local server. When the remote server uploading is completed, you are deleting the uploaded file from the local server.

View:
Create a file called upload_view.php in application/views and place the uploading form HTML in this file.

I hope you like this Post, Please feel free to comment below, your suggestion and problems if you face - we are here to solve your problems.

Arjun
I am Arjun from Hyderabad (India). I have been working as a software engineer from last 7+ years, and its my passion to learn new things and implement them as a practice. Aside from work, I likes gardening and spending time with pets.
DMCA.com Protection Status