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.7K

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

Alaz

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 ☕️

Welcome to PostSrc V3

PostSrc Dark Logo

You have to login to favorite this