I have a form with html browse type and a submit button. I chose a file using browse button and submit the form. On form submission following code is called.
$conn_id="myid";
$conn_id = ftp_connect ( 'server' );
$ftp_user_name="username";
$ftp_user_pass="password";
// login with username and password
$login_result = ftp_login ( $conn_id , $ftp_user_name , $ftp_user_pass );
// check connection
if ((! $conn_id ) || (! $login_result )) {
echo "FTP connection has failed!" ;
exit;
} else {
echo "Connected to for user $ftp_user_name" ;
}
// upload the file
$upload = ftp_put( $conn_id, "images/signatures/" . $fileName , $_FILES['tmp_name'] , FTP_BINARY );
// check upload status
if(!$upload){
echo "FTP upload has failed!" ;
} else {
echo "Successfully Uploaded." ;
}
But it produce the following warning:
Warning: ftp_put(): Filename cannot be empty in /var/www/echdp/_ProviderSignature.php on line 70 FTP upload has failed!
But when I hard code the source path in above code then it upload the file on server:
$upload = ftp_put( $conn_id, "images/signatures/myfile.txt" , "/var/www/images/hello.txt" , FTP_BINARY );