相关文章推荐
Authentication Services
Command Line Specific Extensions
Compression and Archive Extensions
Cryptography Extensions
Database Extensions
Date and Time Related Extensions
File System Related Extensions
Human Language and Character Encoding Support
Image Processing and Generation
Mail Related Extensions
Mathematical Extensions
Non-Text MIME Output
Process Control Extensions
Other Basic Extensions
Other Services
Search Engine Extensions
Server Specific Extensions
Session Extensions
Text Processing
Variable and Type Related Extensions
Web Services
Windows Only Extensions
XML Manipulation
GUI Extensions
Keyboard Shortcuts
?
This help
Next menu item
Previous menu item
Previous man page
Next man page
Scroll to bottom
Scroll to top
Goto homepage
Goto search
(current page)
Focus search box
ftp_nb_fput (
FTP\Connection $ftp ,
string $remote_filename ,
resource $stream ,
int $mode = FTP_BINARY ,
int $offset = 0
): int ftp_nb_fput() 把已打开的文件内容存储到远程 FTP 服务器 本函数和 ftp_fput() 函数的区别是 本函数是异步上传文件。 所以在文件上传过程中,你的程序还可以执行其他操作。 <?php

$file
= 'index.php' ;

$fp = fopen ( $file , 'r' );

$ftp = ftp_connect ( $ftp_server );

$login_result = ftp_login ( $ftp , $ftp_user_name , $ftp_user_pass );

// 初始化上传
$ret = ftp_nb_fput ( $ftp , $file , $fp , FTP_BINARY );
while (
$ret == FTP_MOREDATA ) {

// 任何其他需要做的操作
echo "." ;

// 继续上传...
$ret = ftp_nb_continue ( $ftp );
}
if (
$ret != FTP_FINISHED ) {
echo
"There was an error uploading the file..." ;
exit(
1 );
}

fclose ( $fp );
?>
  • ftp_nb_put() - 存储一个文件至 FTP 服务器(non-blocking)
  • ftp_nb_continue() - 连续获取/发送文件(以不分块的方式 non-blocking)
  • ftp_put() - 上传文件到 FTP 服务器
  • ftp_fput() - 上传已打开的文件到 FTP 服务器
  • There is an easy way to check progress while uploading a file.  Just use the ftell function to watch the position in the file handle.  ftp_nb_fput will increment the position as the file is transferred.

    Example:

    <?

    $fh = fopen ($file_name, "r");
    $ret = ftp_nb_fput ($ftp, $file_name, $fh, FTP_BINARY);
    while ($ret == FTP_MOREDATA) {
    print ftell ($fh)."\n";
    $ret = ftp_nb_continue($ftp);
    }
    if ($ret != FTP_FINISHED) {
    print ("error uploading\n");
    exit(1);
    }
    fclose($fh);

    ?>

    This will print out the number of bytes transferred thus far, every time the loop runs.  Coverting this into a percentage is simply a matter of dividing the number of bytes transferred by the total size of the file.
     
    推荐文章