What is the difference between ftp_put() and ftp_fput() in PHP when uploading files via FTP, and how do they impact file transfers?

When uploading files via FTP in PHP, the main difference between ftp_put() and ftp_fput() is that ftp_put() takes a file pointer resource as input, while ftp_fput() takes a local file path. Using ftp_fput() can simplify the process as it directly uploads a local file without needing to open it first. This can make the code cleaner and more efficient for file transfers.

// Using ftp_fput() to upload a file via FTP
$localFile = 'local_file.txt';
$remoteFile = 'remote_file.txt';

$ftpConnection = ftp_connect('ftp.example.com');
ftp_login($ftpConnection, 'username', 'password');

$localHandle = fopen($localFile, 'r');
ftp_fput($ftpConnection, $remoteFile, $localHandle, FTP_BINARY);

fclose($localHandle);
ftp_close($ftpConnection);