Posts Tagged ‘ftp file upload’

How to connect to FTP and upload file using php code?

Saturday, April 3, 2010 3:15 No Comments

How to connect to FTP and upload file using php code?
The following code will connect to the ftp and upload the file to the server using php code

<?php

$ftp_server=”HOST NAME”;
$ftp_user_name=”USER NAME”;
$ftp_user_pass=”PASSWORD”;
$conn_id = ftp_connect($ftp_server);

// login with username and password

$login_result = ftp_login($conn_id, “$ftp_user_name”, “$ftp_user_pass”);

if ((!$conn_id) || (!$login_result)) {
echo “authentication failed”;
}
else
{

$source_file=”uploads/”.$fileName;
$destination_file=”/htdocs/”.$fileName;
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);

}

ftp_quit($conn_id);

?>

This was posted under category: PHP Tags: ,