Amran
Amran

Reputation: 657

ftp_put() - Unable to Move File to Remote Server

I want to move an uploaded file to a remote server but there is an error on the ftp_put() function. The error is:

Warning: ftp_put(C:\xampp\tmp\php1296.tmp): 
failed to open stream: No such file or directory in 
C:\xampp\htdocs\intranet\admin_cuti\slip-gaji\insert-slip.php on line 65
There was a problem while uploading C:\xampp\tmp\php1296.tmp

May I know how to solve the issue?

New error found :

Warning: ftp_put(): Prohibited file name: 
/public_html/procurement/uploads/C:\xampp\tmp\php1A14.tmp in
C:\xampp\htdocs\intranet\admin_cuti\slip-gaji\insert-slip.php on line 69
There was a problem while uploading C:\xampp\tmp\php1A14.tmp

Below are the codes that I did

UPDATED WITH CORRECT ANSWERS :

$temp_fpath = $_FILES['slip_gaji']['tmp_name'];
$fname = date('d-m-Y-H-i-s') . '-' . $_FILES['slip_gaji']['name'];

$ftp_server = "ftp.domain.com.my";
$ftp_user_name = 'myusername';
$ftp_user_pass = 'mypassword';
$file = $temp_fpath; 
$remote_file = "/public_html/procurement/uploads/" . $fname;

// set up a connection or die
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server"); 

// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);

// turn passive mode on
ftp_pasv($conn_id, true);

// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_BINARY)) {
    echo "successfully uploaded $file\n";
} else {
    echo "There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id); 

Upvotes: 2

Views: 979

Answers (1)

Samuel Aiala Ferreira
Samuel Aiala Ferreira

Reputation: 694

The problem is that C:\xampp\tmp\php1296.tmp doesn't exists.

The /tmp/php* files are usually generated when you submit a web form, to use toghether with move_upload_file function, and they are deleted once the scripts ends

To use the ftp_put you have to know the path of the file.

Upvotes: 1

Related Questions