Created
August 2, 2016 19:41
-
-
Save ethanpil/2432a764619430f62d77f4a330105e95 to your computer and use it in GitHub Desktop.
Upload file via FTP in Curl
This file contains 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 | |
$ch = curl_init(); | |
$localfile = '/path/to/file.zip'; | |
$remotefile = 'filename.zip'; | |
$fp = fopen($localfile, 'r'); | |
curl_setopt($ch, CURLOPT_URL, 'ftp://ftp_login:[email protected]/'.$remotefile); | |
curl_setopt($ch, CURLOPT_UPLOAD, 1); | |
curl_setopt($ch, CURLOPT_INFILE, $fp); | |
curl_setopt($ch, CURLOPT_INFILESIZE, filesize($localfile)); | |
curl_exec ($ch); | |
$error_no = curl_errno($ch); | |
curl_close ($ch); | |
if ($error_no == 0) { | |
$error = 'File uploaded succesfully.'; | |
} else { | |
$error = 'File upload error.'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment