【发布时间】:2015-11-30 14:45:16
【问题描述】:
您好,这是我使用 Laravel5 和 Storage Facade 为虚拟磁盘下载文件的代码(非常简单):
//implemented as a Artisan Console command
$contents = Storage::disk('remoteDisk')->get($filePath);
Storage::disk('csv')->put($filePathTarget, $contents);
我想在输出中看到一个进度条,就像文档建议的那样:
$bar = $this->output->createProgressBar($count);
//do something
$bar->advance();
//i'm done
$bar->finish();
既然 Storage 方法 get() 不是循环,我如何“推进”进度条?
初始化可能是:
$size_remote = Storage::disk('remoteDisk')->size($filePath);
$size = Storage::disk('csv')->size($filePath);
但是如何/在哪里获取临时文件文件大小以在下载期间推进进度条?
【问题讨论】:
-
您可能不能,因为 Storage 门面不使用流进行读取。如果要使用流,您可以构建上下文并将
stream_notification_callback与STREAM_NOTIFY_PROGRESS代码一起使用。你可以用 Flysystem 来做,但看起来你不能通过存储门面来使用它。
标签: laravel download progress-bar storage