How to Get File Size from URL in Laravel?

Today now in this post i will show you How to Get File Size from URL in Laravel? Sometimes you need to get the file size from the path in laravel. So if we need to get the file size from url then no worry . Beacuase we can get this by using File facade. File facade provide us the several function on that way we can get the size of file or image.

We will able to get the file size from path in laravel 6, laravel 7 and laravel 8 any version in laravel.

Now in the bellow example i will give you a path of my images folder inside the public folder and one image, that will give path as a 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);
    }
}

Read Also: How to convert file extension using CloudConvert in laravel?

Thanks for read. I hope it help you. For more you can follow us on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →