Skip to content

Instantly share code, notes, and snippets.

@rajankur
Last active August 29, 2015 14:14
Show Gist options
  • Select an option

  • Save rajankur/63db1354a19c414d06dd to your computer and use it in GitHub Desktop.

Select an option

Save rajankur/63db1354a19c414d06dd to your computer and use it in GitHub Desktop.
PHP: upload files via FTP
<?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