导航首页 » 技术教程 » PHP:ftp_fput()的用法_FTP函数
PHP:ftp_fput()的用法_FTP函数 127 2023-12-17   

ftp_fput

(PHP 4, PHP 5)

ftp_fput — 上传一个已经打开的文件到 FTP 服务器

说明

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

ftp_fput() 函数用来上传一个在已经打开的文件中的数据到 FTP 服务器。

参数

ftp_stream

FTP 连接的链接标识符。

remote_file

远程文件路径。

handle

打开的本地文件句柄,读取到文件末尾。

mode

传输模式只能为 (文本模式) FTP_ASCII 或 (二进制模式) FTP_BINARY 其中的一个。

startpos

远程文件上传的开始位置。

返回值

成功时返回 TRUE, 或者在失败时返回 FALSE

范例

Example #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 $filen";
} else {
    echo "There was a problem while uploading $filen";
}

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



!!!站长长期在线接!!!

网站、小程序:定制开发/二次开发/仿制开发等

各种疑难杂症解决/定制接口/定制采集等

站长微信:lxwl520520

站长QQ:1737366103