Laravel - get size from uploaded file

前端 未结 4 1989
既然无缘
既然无缘 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:55

    Laravel 5

    $request->file('file')->getSize();
    

    Laravel 4

    $request->file('file')->getClientSize(); // getClientSize() is deprecated in Laravel 5
    
    0 讨论(0)
  • 2021-01-07 17:57
    getClientSize() is deprecated starting version 4.1. Use getSize() instead.
    

    https://github.com/symfony/symfony/blob/4.1/UPGRADE-4.1.md#httpfoundation

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-07 18:10

    Very simple(Proper Laravel Way):

    //add this at the top of your controller
    use File;
    
    // add this with in your function
    $size = File::size($PATH_OF_FILE);
    
    0 讨论(0)
提交回复
热议问题