How can PHP support file transfers over different protocols like HTTP and FTP?
PHP can support file transfers over different protocols like HTTP and FTP by utilizing built-in functions such as `file_get_contents()` and `file_put_contents()` for HTTP transfers, and `ftp_put()` and `ftp_get()` for FTP transfers. These functions allow PHP to read from or write to remote files using the specified protocol.
// Example of transferring a file over HTTP
$file_url = 'http://example.com/file.txt';
$contents = file_get_contents($file_url);
file_put_contents('local_file.txt', $contents);
// Example of transferring a file over FTP
$ftp_server = 'ftp.example.com';
$ftp_username = 'username';
$ftp_password = 'password';
$remote_file = '/remote_file.txt';
$local_file = 'local_file.txt';
$ftp_conn = ftp_connect($ftp_server);
ftp_login($ftp_conn, $ftp_username, $ftp_password);
ftp_get($ftp_conn, $local_file, $remote_file, FTP_BINARY);
ftp_close($ftp_conn);