Skip Navigation LinksHome > Categories > Code from a Category

Uploading files to FTP

User Name: serfcompany
Name: Serf
Contact Me:
Home Page:
php,mysql,javascript,html,css. Preferable working with Zend Framework. Good know javascript. I worked with various, javascript frameworks such as(jquery, YUI3, extjs, sencha touch). [More]
Viewed Times: 1702
Add Date: 02/26/2012
Any site administrator wants that to visitors to his site was larger and the traffic that they eat, was small. To do this, they offer free FTP accounts, which allow free upload and download files of small size (usually less than 10 MB). In this case, the problem arises automatically upload files to FTP. In this article I will show you how to use a small PHP function help you maximum the task.

Create a small file upload form:

Please note that upl.php, is the name of the file where data is transmitted, which should contain a function of processing and uploading the file. Also, in describing the form, you must specify a string

which allows you to upload any data. If you have not downloaded the file on the FTP, first check that you have added this feature.

Code the file upl.php:

$ login and $ pass - username and password of your FTP account
$ host - the name of your FTP (for example,
$ path - the inner path to the folder where you want to download the file (permissions for this folder must be on record).
For example / alex / download / upload /.

Determine the name of the temporary file to upload. It is necessary to explain the principle of the file download.
Once you have clicked on the "Import" button, the file was placed in a temporary directory on your server (usually a folder tmp).
Only then we can work with this file and send it to the right place.
Usually, the contents of the folder tmp is destroyed automatically, but that would be safe at the end of all operations necessary to delete the file itself

Now you need to connect to FTP:

Immediately check to see if a connection is absent ($ connect = false) or has an invalid login data and / or password ($ result = false) then stop execution of the function.

Further, by using the ftp_chdir go into the folder $ path and load the file by using ftp_put:

The file is loaded, now need to disconnect from the FTP and delete the temporary file:

Now feasible function call:

If the user selects a file ($ filename is not empty), then load the file on the ftp.

Post a Comment

Name: (Optional)
Email: (Optional, you can get an email if somebody replys your comments)*
Email me if somebody respons my comment below:
Enter Text
as Below:
(case insensitive, if hard to read, click the "get a new one" button)
* Your email address will not be shared with any third parties for any reason.
** Maximum 1000 charactors.