我用这个命令保存了一个文件
$newFile = [
'event_id' => $event->id,
'path' => $storePath
];
EventFile::create($newFile);
Run Code Online (Sandbox Code Playgroud)
我可以获得这样一个链接的文件路径:
Storage::disk('public')->url($file->path);
Run Code Online (Sandbox Code Playgroud)
但是没有关于文件大小的数据.如何在刀片视图中获取文件大小???
Art*_*vič 48
Laravel 5
$request->file('file')->getSize();
Run Code Online (Sandbox Code Playgroud)
Laravel 4
$request->file('file')->getClientSize(); // getClientSize() is deprecated in Laravel 5
Run Code Online (Sandbox Code Playgroud)
Storage Facade如果您已经存储/上传文件,则更简单的方法是使用
use Illuminate\Support\Facades\Storage;
public function get_size($file_path)
{
return Storage::size($file_path);
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您使用的是S3Bucket,那么您可以像下面一样修改上述功能
use Illuminate\Support\Facades\Storage;
public function get_size($file_path)
{
return Storage::disk('s3')->size($file_path);
}
Run Code Online (Sandbox Code Playgroud)
getClientSize() is deprecated starting version 4.1. Use getSize() instead.
Run Code Online (Sandbox Code Playgroud)
https://github.com/symfony/symfony/blob/master/UPGRADE-4.1.md#httpfoundation
| 归档时间: |
|
| 查看次数: |
30712 次 |
| 最近记录: |