How to Get File Size From Public Storage in Laravel

  Dec 2023
  ITSolutionsGuides
  Category: Laravel
How to Get File Size From Public Storage in Laravel

Welcome To ITSolutionsGuides,

Lets learn How to Get File Size From Public Storage in Laravel using the it solutions guides tutorial. To get any file size in laravel first we need to get the file using the Storage facade and also the File facade provided by the Laravel. Once the file is fetched then we can get the file size using the size. We can also get any file size present in the internet by providing the exact path of the file to fetch and then get the size of the file. so lets see How to Get File Size From Public Storage in Laravel.
Retrieve file size in Laravel public storage using Storage facade. Specify path, then use size method with it solutions guides.

Let's Start Coding

In this example lets use the Storage to get or retrive the file from the storage and the get the size of the image or file using the size

<?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('uploads/a.jpg');;
  
        dd($fileSize);
    }
}

Let's Start Coding

In this example lets use the File to get or retrive the file from the storage and the get the size of the image or file using the size

<?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('uploads/a.jpg'));
  
        dd($fileSize);
    }
}

We hope it helps everyone. Thanks for supporting ITSolutionsGuides and keep supporting us also follow us in social media platforms.

Subscribe for NewsLetter

Be the first to know about releases and tutorial news and solutions.

We care about your data in our privacy policy.

ITSolutionsGuides

ITSolutionsGuides was started mainly to provide good and quality web solutions for all the developers. We provide tutorials to support all the developers and also we try to provide solutions to the errors we face while coding.

Contact US

ITSolutionsGuides, provide users with an easy-to-use form to reach out for support or inquiries.

whatsapp  gmail  instagram-new--v1  facebook-circled  twitter-circled  linkedin  github  pinterest 

Copyright © 2023 - 2024 All rights reserved | ITSolutionsGuides