問題描述
如何通過 Storage Facade(在 Laravel 5 中)獲取下載文件的進度條? (How to get a progress bar for downloading a file via Storage Facade (in Laravel 5)?)
您好,這是我用於使用 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);
但是如何/在哪裡獲取臨時文件文件大小以在下載期間推進進度條?
參考解法
方法 1:
It's doable, but you are going to need JavaScript.
Also it's been answered already on StackOverflow here.