ftp_put

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

ftp_put上傳文件到 FTP 服務(wù)器

說(shuō)明

ftp_put(
    resource $ftp_stream,
    string $remote_file,
    string $local_file,
    int $mode = FTP_BINARY,
    int $startpos = 0
): bool

ftp_put() 函數(shù)用來(lái)上傳指定的本地文件到 FTP 服務(wù)器。

參數(shù)

ftp_stream

FTP 連接資源。

remote_file

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

local_file

本地文件路徑。

mode

傳送模式,只能為 FTP_ASCII(文本模式)或 FTP_BINARY(二進(jìn)制模式)。

startpos

指定開(kāi)始上傳的位置,一般用來(lái)文件續(xù)傳。

返回值

成功時(shí)返回 true, 或者在失敗時(shí)返回 false。

更新日志

版本 說(shuō)明
7.3.0 mode 參數(shù)為可選,之前版本中為必選。

范例

示例 #1 ftp_put() 實(shí)例

<?php
$file 
'somefile.txt';
$remote_file 'readme.txt';

// 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);

// upload a file
if (ftp_put($conn_id$remote_file$fileFTP_ASCII)) {
 echo 
"successfully uploaded $file\n";
} else {
 echo 
"There was a problem while uploading $file\n";
}

// close the connection
ftp_close($conn_id);
?>

參見(jiàn)

  • ftp_pasv() - 返回當(dāng)前 FTP 被動(dòng)模式是否打開(kāi)
  • ftp_fput() - 上傳一個(gè)已經(jīng)打開(kāi)的文件到 FTP 服務(wù)器
  • ftp_nb_fput() - 將文件存儲(chǔ)到 FTP 服務(wù)器 (非阻塞)
  • ftp_nb_put() - 存儲(chǔ)一個(gè)文件至 FTP 服務(wù)器(non-blocking)