PHP Classes

PHP FTP File Upload: Connect to a FTP server and upload files

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 221 All time: 8,265 This week: 78Up
Version License PHP version Categories
ftp-upload 1.0Freely Distributable5Networking, PHP 5, Files and Folders
Description 

Author

This class can connect to a FTP server and upload files.

It can establish a connection to a given FTP server and execute several operations that may be necessary to upload files.

Currently it can check if given server directory exists, create a new directory, upload a file to a given directory.

Picture of Anuj Kumar Gupta
Name: Anuj Kumar Gupta <contact>
Classes: 1 package by
Country: India India

 

Example

<?php
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST)) {
   
//Define your host, username, password and directory name
   
define('FTP_HOST', 'FTP Host/IP Name');
   
define('FTP_USER', 'FTP User Name');
   
define('FTP_PASS', 'FTP Password');
   
define('DIR_NAME', 'Your Directory Name');
   
   
//Post file element
   
$arrPostFile = $_FILES['fleFile'];

   
//Include the class
   
include('class.ftpupload.php');

   
//Create the FTP object
   
$ftpObj = new FTPClient();

   
//Connect
   
$ftpObj->connect(FTP_HOST, FTP_USER, FTP_PASS);

   
//Make directory
   
$ftpObj->makeDir(DIR_NAME);
   
   
//Upload local file to new directory on server
   
$ftpObj->uploadFile($arrPostFile, DIR_NAME);

   
//Display message
   
$ftpObj->pr($ftpObj->getMessages());
}
?>

<form action="" method="post" enctype="multipart/form-data">
    <label>File:</label><input type="file" name="fleFile" id="fleFile" /><br />
    <input type="submit" value="upload" />
</form>


  Files folder image Files (2)  
File Role Description
Accessible without login Plain text file index.php Example Example Script
Plain text file class.ftpupload.php Class FTP File upload class

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:221
This week:0
All time:8,265
This week:78Up