DEV Community

Cover image for How to Get File Size on Uploaded file in Laravel 8
Code And Deploy
Code And Deploy

Posted on • Edited on

6 2

How to Get File Size on Uploaded file in Laravel 8

Originally posted @ https://codeanddeploy.com visit and download the sample code: https://codeanddeploy.com/blog/laravel/how-to-get-file-size-on-uploaded-file-in-laravel-8

Advanced Laravel SAAS Starter Kit with CRUD Generator

Advanced Laravel SAAS Starter Kit with CRUD Generator - GET YOUR COPY NOW!

In this post, I will share a short solution on how to determine the file size on uploaded files in Laravel 8. Sometimes we need to check first the user file uploaded to our server if meets our standard size before saving it.

So here's how should do it.

First, create your post route.



Route::post('/files/add', 'FilesController@store')->name('files.store');


Enter fullscreen mode Exit fullscreen mode

Then in your controller let's create a store method.



/**
* Store a newly created resource in storage.
*
* @param  Request  $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
    echo $request->file->getSize();
}


Enter fullscreen mode Exit fullscreen mode

Then that's it you will know if what is the byte size of your file and convert it to MB or KB.

Advanced Laravel SAAS Starter Kit with CRUD Generator

Advanced Laravel SAAS Starter Kit with CRUD Generator - GET YOUR COPY NOW!

I hope this tutorial can help you. Kindly visit here https://codeanddeploy.com/blog/laravel/how-to-get-file-size-on-uploaded-file-in-laravel-8 if you want to download this code.

Happy coding :)

Heroku

Amplify your impact where it matters most — building exceptional apps.

Leave the infrastructure headaches to us, while you focus on pushing boundaries, realizing your vision, and making a lasting impression on your users.

Get Started

Top comments (0)

👋 Kindness is contagious

Engage with a wealth of insights in this thoughtful article, valued within the supportive DEV Community. Coders of every background are welcome to join in and add to our collective wisdom.

A sincere "thank you" often brightens someone’s day. Share your gratitude in the comments below!

On DEV, the act of sharing knowledge eases our journey and fortifies our community ties. Found value in this? A quick thank you to the author can make a significant impact.

Okay