ftp_fput
(PHP 4, PHP 5, PHP 7, PHP 8)
ftp_fput — 上傳一個已經打開的檔案到 FTP 伺服器
說明
     ftp_fput(
resource
string
resource
int
int
): bool
    resource
$ftp_stream,string
$remote_file,resource
$handle,int
$mode,int
$startpos = 0): bool
ftp_fput() 函式用來上傳一個在已經打開的檔案中的數據到 FTP 伺服器。
參數
- 
ftp_stream
- 
      FTP 連線的鏈接識別符號。 
- 
remote_file
- 
      遠端檔案路徑。 
- 
handle
- 
      打開的本地檔案控制代碼,讀取到檔案末尾。 
- 
mode
- 
      傳輸模式只能為 (文字模式) FTP_ASCII或 (二進制模式)FTP_BINARY其中的一個。
- 
startpos
- 
      遠端檔案上傳的開始位置。 
返回值
   成功時返回 true, 或者在失敗時返回 false。
  
範例
示例 #1 ftp_fput() 例子
<?php
// open some file for reading
$file = 'somefile.txt';
$fp = fopen($file, 'r');
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to upload $file
if (ftp_fput($conn_id, $file, $fp, FTP_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);
?>
更新日誌
| 版本 | 說明 | 
|---|---|
| 4.3.0 | 新增了 startpos的支援。 | 
參見
- ftp_put() - 上傳檔案到 FTP 伺服器
- ftp_nb_fput() - 將檔案儲存到 FTP 伺服器 (非阻塞)
- ftp_nb_put() - 儲存一個檔案至 FTP 伺服器(non-blocking)