首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ftp_nb_put

(PHP 4 >= 4.3.0, PHP 5, PHP 7)

ftp_nb_put - 在FTP服务器上存储文件(非阻塞)

描述

代码语言:javascript
复制
int ftp_nb_put ( resource $ftp_stream , string $remote_file , string $local_file , int $mode [, int $startpos = 0 ] )

ftp_nb_put()将一个本地文件存储在FTP服务器上。

这个函数和ftp_put()的区别在于这个函数是异步上传文件的,所以你的程序可以在文件上传时执行其他操作。

参数

ftp_stream

FTP连接的链接标识符。

remote_file

远程文件路径。

local_file

本地文件路径。

mode

传输模式。必须是FTP_ASCII或者FTP_BINARY

startpos

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

返回值

返回FTP_FAILEDFTP_FINISHEDFTP_MOREDATA

例子

示例#1 ftp_nb_put()示例

代码语言:javascript
复制
<?php

// Initiate the Upload
$ret = ftp_nb_put($my_connection, "test.remote", "test.local", FTP_BINARY);
while ($ret == FTP_MOREDATA) {
   
   // Do whatever you want
   echo ".";

   // Continue uploading...
   $ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
   echo "There was an error uploading the file...";
   exit(1);
}
?>

示例#2使用ftp_nb_put()恢复上载

代码语言:javascript
复制
<?php

// Initiate
$ret = ftp_nb_put($my_connection, "test.remote", "test.local", 
                      FTP_BINARY, ftp_size("test.remote"));
// OR: $ret = ftp_nb_put($my_connection, "test.remote", "test.local", 
//                           FTP_BINARY, FTP_AUTORESUME);

while ($ret == FTP_MOREDATA) {
   
   // Do whatever you want
   echo ".";

   // Continue uploading...
   $ret = ftp_nb_continue($my_connection);
}
if ($ret != FTP_FINISHED) {
   echo "There was an error uploading the file...";
   exit(1);
}
?>

扫码关注腾讯云开发者

领取腾讯云代金券