Skip to content

Instantly share code, notes, and snippets.

@microdesign
Created October 14, 2015 11:40
Show Gist options
  • Save microdesign/aaa999d77903c13a952e to your computer and use it in GitHub Desktop.
Save microdesign/aaa999d77903c13a952e to your computer and use it in GitHub Desktop.
Simple FTP Class
<?php
/**
* Created by PhpStorm.
* User: mtonev
* Date: 10/14/15
* Time: 11:01 AM
*/
class FTP {
private $connection;
private $dir = '/public_html/files/';
const SERVER = '';
const USER = '';
const PASS = '';
public function connect()
{
$this->connection = $conn_id = ftp_connect(self::SERVER);
$login_result = ftp_login($conn_id, self::USER, self::PASS);
if ((!$conn_id) || (!$login_result))
{
die("FTP connection has failed!");
}
return $this;
}
public function upload($file, $destination)
{
$upload = ftp_put($this->connection, $this->dir.$destination, $file, FTP_BINARY);
return ( ! $upload) ? false : true;
ftp_close($this->connection);
}
}
/* Usage */
$ftp = new FTP();
$ftp->connect()
->upload(basename($_FILES['file']['tmp_name']), $dest);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment