示例 #1 FTP 例程
<?php
// 建立基礎(chǔ)連接
$conn_id = ftp_connect($ftp_server);
// 使用用戶名和口令登錄
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// 檢查是否成功
if ((!$conn_id) || (!$login_result)) {
echo "FTP connection has failed!";
echo "Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo "Connected to $ftp_server, for user $ftp_user_name";
}
// 上傳文件
$upload = ftp_put($conn_id, $destination_file, $source_file, FTP_BINARY);
// 檢查上傳結(jié)果
if (!$upload) {
echo "FTP upload has failed!";
} else {
echo "Uploaded $source_file to $ftp_server as $destination_file";
}
// 關(guān)閉 FTP 流
ftp_close($conn_id);
?>