How to Get File Size from Storage in Laravel?

By Hardik Savani April 16, 2024 Category : Laravel

We sometimes require to get file size from path in laravel, so if you need to get file size from url then no worry and you can get using File facade. File facade provide several function that way we can get size of file or image.

you will able to get file size from path in laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version1

In bellow example i just give you path of my images folder inside public folder and one image, that give path as argument of size function:

Example 1: using Storage

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Storage;

class DemoController extends Controller

{

/**

* Create a new controller instance.

*

* @return void

*/

public function index()

{

$fileSize = Storage::size('public/settings/file.jpg');;

dd($fileSize);

}

}

Example 2: Using File

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use File;

class DemoController extends Controller

{

/**

* Create a new controller instance.

*

* @return void

*/

public function index()

{

$fileSize = File::size(public_path('images/1461177230.jpg'));

dd($fileSize);

}

}

I hope it can help you...

Tags :
Shares