Last active
August 29, 2015 14:14
-
-
Save rajankur/63db1354a19c414d06dd to your computer and use it in GitHub Desktop.
PHP: upload files via FTP
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 | |
| /** | |
| * FTP upload lets you upload files to the server via FTP | |
| * @param string $host -host name of the server goes here | |
| * @param string $ftp_user -FTP username | |
| * @param string $ftp_pwd -FTP password | |
| * @param string $filename -filename to save with | |
| * @param string $content -content of the file | |
| * @return boolean | |
| */ | |
| function ftpUpload($host,$ftp_user,$ftp_pwd,$filename,$content) | |
| { | |
| $ftp_conn = ftp_connect($host); | |
| $ftp_login = ftp_login($ftp_conn, $ftp_user, $ftp_pwd); | |
| $tempHandle = fopen('php://temp', 'r+'); | |
| fwrite($tempHandle, $content); | |
| rewind($tempHandle); | |
| if(ftp_fput($ftp_conn, $filename, $tempHandle, FTP_ASCII)) | |
| { | |
| return 1; | |
| } | |
| else | |
| { | |
| return 0; | |
| } | |
| } | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment