ftp_fput

(PHP 3 >= 3.0.13, PHP 4, PHP 5)

ftp_fput -- 上傳一個已經開啟的檔案到 FTP 伺服器

說明

bool ftp_fput ( resource ftp_stream, string remote_file, resource handle, int mode [, int startpos] )

ftp_fput() 函數用來上傳一個在已經開啟的檔案中的資料到 FTP 伺服器,參數 handle 為所開啟檔案的識別碼。參數 remote_file 為上傳到伺服器上的檔案名。傳輸模式參數 mode 只能為 (文字模式) FTP_ASCII 或 (二進位模式) FTP_BINARY 其中的一個。

例子 1. ftp_fput() example

<?php

// open some file for reading
$file 'somefile.txt';
$fp fopen($file'r');

// connect to the server
$conn_id ftp_connect($ftp_server);
$login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

// try to upload the file
if(ftp_fput($conn_id$file$fpFTP_ASCII)) {
    echo 
"Successfully uploaded $file\n";
} else {
    echo 
"There was a problem while uploading $file\n";
}

// close the connection and the file handler
ftp_close($conn_id);
fclose($fp);

?>

注: 參數 startpos 只適用於 4.3.0 以上版本。

若果成功則返回 TRUE,失敗則返回 FALSE

參見 ftp_put()ftp_nb_fput()ftp_nb_put()