Posts Learn Components Snippets Categories Tags Tools new 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

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

new

PostSrc Code Components

Collection of Tailwind CSS components for everyone to use. Browse all of the components that are right for your project.

View Components
)