ftp_nb_put
(PHP 4 >= 4.3.0, PHP 5, PHP 7, PHP 8)
ftp_nb_put — 存储一个文件至 FTP 服务器(non-blocking)
说明
ftp_nb_put
( resource
$ftp_stream
, string $remote_file
, string $local_file
, int $mode
= FTP_BINARY
, int $startpos
= 0
) : int
ftp_nb_put() 函数用来把本地文件 local_file
存储到 FTP 服务器上由 remote_file
参数指定的路径。
与函数 ftp_put() 不同的是,此函数上传文件的时候采用的是异步传输模式,也就意味着在文件传送的过程中,你的程序可以继续干其它的事情。
参数
-
ftp_stream
-
FTP 连接的链接标识符。
-
remote_file
-
远程文件路径。
-
local_file
-
本地文件路径。
-
mode
-
传输模式选择,可选参数为
FTP_ASCII
(文本模式)或FTP_BINARY
(二进制模式)。 -
startpos
-
指定传输开始的位置,用来续传支持。
返回值
返回 FTP_FAILED
或 FTP_FINISHED
或 FTP_MOREDATA
。
更新日志
版本 | 说明 |
---|---|
7.3.0 |
mode 参数为可选,之前版本中为必填。
|
范例
示例 #1 ftp_nb_put() 示例
<?php
// 初始化
$ret = ftp_nb_put($my_connection, "test.remote", "test.local", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
// 可以同时干其它事
echo ".";
// 继续上传...
$ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
echo "上传过程中发生错误...";
exit(1);
}
?>
示例 #2 使用 ftp_nb_put() 来续传文件
<?php
// 初始化
$ret = ftp_nb_put($my_connection, "test.remote", "test.local",
FTP_BINARY, ftp_size("test.remote"));
// 另一种写法: $ret = ftp_nb_put($my_connection, "test.remote", "test.local",
// FTP_BINARY, FTP_AUTORESUME);
while ($ret == FTP_MOREDATA) {
// 可以同时干其它事情
echo ".";
// 继续上传...
$ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
echo "上传过程中发生错误...";
exit(1);
}
?>
参见
- ftp_nb_fput() - 将文件存储到 FTP 服务器 (非阻塞)
- ftp_nb_continue() - 连续获取/发送文件(以不分块的方式 non-blocking)
- ftp_put() - 上传文件到 FTP 服务器
- ftp_fput() - 上传一个已经打开的文件到 FTP 服务器