Posts Learn Components Snippets Categories Tags Tools About
/

How to get mime type from storage class in Laravel

Learn how to get mime type and file size in bytes easily using Laravel storage class

Created on Jan 25, 2022

395 views

To get the file size in bytes and the mime type/extension type from the Storage class you can define your code like below. Do note that we are accessing the "public" disk but it can be any of your specified disks such as "s3" or "digital ocean space".
<?php

// get size in bytes
Storage::disk('public')->size($pathToFile);

// get mime type
Storage::disk('public')->getMimeType($pathToFile);
The "size" will return the "size" in bytes e.g 16000 bytes.
Storage::disk('public')->size($pathToFile);
While the "getMimeType" will return the type of the file e.g "image/jpeg"
Storage::disk('public')->getMimeType($pathToFile);

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

)