ftp_fput

(PHP 4, PHP 5, PHP 7, PHP 8)

ftp_fput上傳一個(gè)已經(jīng)打開(kāi)的文件到 FTP 服務(wù)器

說(shuō)明

ftp_fput(
    resource $ftp_stream,
    string $remote_file,
    resource $handle,
    int $mode,
    int $startpos = 0
): bool

ftp_fput() 函數(shù)用來(lái)上傳一個(gè)在已經(jīng)打開(kāi)的文件中的數(shù)據(jù)到 FTP 服務(wù)器。

參數(shù)

ftp_stream

FTP 連接的鏈接標(biāo)識(shí)符。

remote_file

遠(yuǎn)程文件路徑。

handle

打開(kāi)的本地文件句柄,讀取到文件末尾。

mode

傳輸模式只能為 (文本模式) FTP_ASCII 或 (二進(jìn)制模式) FTP_BINARY 其中的一個(gè)。

startpos

遠(yuǎn)程文件上傳的開(kāi)始位置。

返回值

成功時(shí)返回 true, 或者在失敗時(shí)返回 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$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);

?>

更新日志

版本 說(shuō)明
4.3.0 添加了 startpos 的支持。

參見(jiàn)

  • ftp_put() - 上傳文件到 FTP 服務(wù)器
  • ftp_nb_fput() - 將文件存儲(chǔ)到 FTP 服務(wù)器 (非阻塞)
  • ftp_nb_put() - 存儲(chǔ)一個(gè)文件至 FTP 服務(wù)器(non-blocking)