Laravel - get size from uploaded file

前端 未结 4 1988
既然无缘
既然无缘 2021-01-07 17:12

I have saved a file with this command

$newFile = [
            \'event_id\' => $event->id,
            \'path\' => $storePath
           ];

EventFi         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 17:58

    The more Simpler way is to use Storage Facade if you have already stored / uploaded file

    use Illuminate\Support\Facades\Storage;
    
    public function get_size($file_path)
    {
        return Storage::size($file_path);
    }
    

    Or if you are using S3 Bucket then you can modify the above function like below

    use Illuminate\Support\Facades\Storage;
    
    public function get_size($file_path)
    {
        return Storage::disk('s3')->size($file_path);
    }
    

    Check Laravel File Storage

提交回复
热议问题