Table of contents
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');
Â
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();
}
Â
Then that's it you will know if what is the byte size of your file and convert it to MB or KB.
Â
I hope it helps. Thank you for reading :)
Â
Cheers :)
Â
Read next