PHP Classes

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

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 220 This week: 1All time: 8,270 This week: 560Up
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
Age: ???
All time rank: 4082279 in India India
Week rank: 411 Up26 in India India Up

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  
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

 Version Control Unique User Downloads Download Rankings  
 0%
Total:220
This week:1
All time:8,270
This week:560Up