Created
October 14, 2015 11:40
-
-
Save microdesign/aaa999d77903c13a952e to your computer and use it in GitHub Desktop.
Simple FTP Class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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