How to Get File Size from Storage in 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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- Laravel Store JSON Format Data in Database Example
- How to Create and Use Stored Procedure in Laravel?
- Laravel Eloquent Left Join Where Null Condition Example
- PHP Copy File from One Folder to Another Example
- PHP Laravel Left Join Query Example
- PHP Laravel Inner Join Query Example
- How to Delete File from Public Folder / Storage Folder in Laravel?
- Laravel Move File from One Folder to Another Example
- Laravel Copy File from One Folder to Another Example
- How to Display Image from Storage Folder in Laravel?
- Laravel Storage Dropbox Integration Example
- How to Create Zip File in Laravel?
- Laravel Eloquent Inner Join with Multiple Conditions Example
- How to Count Files in a Directory using Laravel?
- Laravel Create JSON File & Download From Text Example