Laravel - get size from uploaded file

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


getClientSize() is deprecated starting version 4.1. Use getSize() instead.

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


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);

Laravel 5^

$request->file('file')->getSize(); // in bytes

Laravel 4

$request->file('file')->getClientSize(); // getClientSize() is deprecated in Laravel 5

Tags:

Laravel