Home / Snippets / How to get mime type from storage class in Laravel
How to get mime type from storage class in Laravel cover

How to get mime type from storage class in Laravel

1.5K

2 years ago

0 comments

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);
notion avatar

Ahmad Aziz

Week-end developer currently experimenting with web, mobile, and all things programming.

Topics:

Frontend

Resource

Average

Average

Support Us

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

Post Tutorials

Learn trending tutorials for ReactJs, React Native, VueJS, NextJs, Laravel, Tailwind CSS, and Flutter development.
View Tutorials

Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that's right for your web projects
View Components

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this