PHP显示ftp_get的进度百分比? [英] PHP Display a percentage of progress of ftp_get?

查看:222
本文介绍了PHP显示ftp_get的进度百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个可用的FTP文件下载脚本。

我正在下载的文件大约每天2-4 GB。

我想知道是否有办法获取文件所在的百分比?



我已经查看了php.net和这里,但我找不到任何类似的问题,而是花更多的时间寻找我想我会问人们比我更聪明。



我在想如果有一个函数可以看到它下载的位置,但我找不到一个是因为 ftp_get 必须先完成,这样就消除了每隔几秒刷新缓冲区以显示新百分比的机会。



任何人?



以下是我的代码:我将所有变量隐藏在上面。

  $ conn_id = ftp_connect($ ftp_server); 

$ login_result = ftp_login($ conn_id,$ ftp_user_name,$ ftp_user_pass);
$ b $ if(ftp_get($ conn_id,$ local_file,$ server_file,FTP_BINARY)){
echo成功写入$ local_file \ n;
} else {
echoThere's a problem \\\
;
}

ftp_close($ conn_id);






编辑:

我添加了 ftp_nb_get ,这里是我的代码。
$ b

  $ ret = ftp_nb_get($ conn_id,$ local_file ,$ server_file,FTP_BINARY,$ size); 
while($ ret == FTP_MOREDATA){
echo round((filesize($ local_file)/ $ server_size)* 100)。%\ n;
$ ret = ftp_nb_continue($ conn_id);


解决方案

尝试使用非阻塞版本 ftp_nb_get() ftp_nb_continue( ) ,并检查保存的文件的大小。


I have a working FTP file download script.
The files I am downloading will be about 2-4 GB per day.
I was wondering if there was a way to get the percent of the file where it's at?

I have looked on php.net and on here but I couldn't find any similar questions and rather spend more time looking I figure I would ask people much smarter than myself.

I was thinking about if there was a function to see where it's at in the download, but I couldn't find one since ftp_get would have to complete first so that eliminated the chance of flushing the buffer every few seconds to display a new percent.

Anyone?

Here is my code: I hid all of my variables above it.

$conn_id = ftp_connect($ftp_server);

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

if (ftp_get($conn_id, $local_file, $server_file, FTP_BINARY)) {
    echo "Successfully written to $local_file\n";
} else {
    echo "There was a problem\n";
}

ftp_close($conn_id);


EDIT:

I added ftp_nb_get and here is my code for that. It keeps downloading fine, just doesn't echo it out to the browser.

$ret = ftp_nb_get($conn_id, $local_file, $server_file, FTP_BINARY, $size);
while ($ret == FTP_MOREDATA) {
  echo round((filesize($local_file)/$server_size)*100)."%\n";
  $ret = ftp_nb_continue($conn_id);
}

解决方案

Try using the non-blocking version ftp_nb_get() and ftp_nb_continue() in a loop, and check for the saved file's size.

这篇关于PHP显示ftp_get的进度百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆