ftp_nb_put
ftp_nb_put
(PHP 4 >= 4.3.0, PHP 5, PHP 7)
ftp_nb_put - 在FTP服务器上存储文件(非阻塞)
描述
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_FAILED
或FTP_FINISHED
或FTP_MOREDATA
。
例子
示例#1 ftp_nb_put()示例
<?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()恢复上载
<?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
}
?>