Inside this article we will see see the concept to get file size from url in laravel 8 tutorial. Article contains classified information about finding file size via URL.
If you are looking for an article which gives you the understanding to find file size from URL, file is of any type then you are at right place to learn.
Laravel provides few options to get file size from path. In this article we will use the concept of getting file size using Storage class and File class. We need to assume that we have few files inside /public folder or /storage/app/public folder.
Learn More –
- Create Signature Pad & Save Using jQuery in Laravel 8
- Crop Image Before Upload Using Croppie.js in Laravel 8
- Customization of Markdown Mailable Email Templates
- Eloquent Mutators and Accessors in Laravel 8 Tutorial
Let’s get started.
Laravel Installation
We will create laravel project using composer. So, please make sure your system should have composer installed. If not, may be this article will help you to Install composer in system.
Here is the command to create a laravel project-
composer create-project --prefer-dist laravel/laravel blog
To start the development server of Laravel –
php artisan serve
URL: http://127.0.0.1:8000
Assuming laravel already installed inside your system.
Files Inside images Folder
Let’s say we have an image file inside /public folder.
Also we can calculate file size from /storage folder.
We will calculate the size of that file using Storage class and File class.
File Size: Using Storage Class
Say we have a file named as 1.png inside /storage/app/public/images folder.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; class SampleController extends Controller { public function index() { $fileSize = Storage::size('public/images/1.png'); // File size in bytes dd($fileSize); } }
Output
File size will be returned into bytes.
File Size: Using File Class
Say we have a file named as 1.png inside /public/images folder.
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use File; class SampleController extends Controller { public function index() { $fileSize = File::size(public_path('images/1.png')); // File size in bytes dd($fileSize); } }
Output
File size will be returned into bytes.
We hope this article helped you to learn How To Get File Size From URL in Laravel 8 Tutorial in a very detailed way.
Online Web Tutor invites you to try Skillshike! Learn CakePHP, Laravel, CodeIgniter, Node Js, MySQL, Authentication, RESTful Web Services, etc into a depth level. Master the Coding Skills to Become an Expert in PHP Web Development. So, Search your favourite course and enroll now.
If you liked this article, then please subscribe to our YouTube Channel for PHP & it’s framework, WordPress, Node Js video tutorials. You can also find us on Twitter and Facebook.