ItSolutionStuff.com

Laravel Get File Mime Type from Storage Example

By Hardik Savani β€’ November 5, 2023
Laravel

Hello Folks,

This article goes in detailed on laravel storage get mime type. This article goes in detailed on laravel get mime type from url. let’s discuss about how to get mime type of file in laravel. This article goes in detailed on how to get mime type in laravel.

Laravel offers the Storage and File facades for managing file systems. In this guide, I will demonstrate how to retrieve file mime type from both the storage and public folders within Laravel. You can refer to the following examples to learn how to access file content.

Review the following one by one example:

Example 1: Laravel Get File Mime Type using Storage

here is a controller code of getting file mime type from Storage facade.

app/Http/Controllers/FileController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use Illuminate\Support\Facades\Storage;

class FileController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$mimeType = Storage::mimeType('upload/test.txt');

dd($mimeType);

}

}

Output:

text/plain

Example 2: Laravel Get File Mime Type using using File

here is a controller code of getting file mime type from File facade.

app/Http/Controllers/FileController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use File;

class FileController extends Controller

{

/**

* Display a listing of the resource.

*

* @return \Illuminate\Http\Response

*/

public function index()

{

$mimeType = File::mimeType('upload/test.txt');

dd($mimeType);

}

}

Output:

text/plain

I hope it can help you...

Tags: Laravel
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

πŸ“Ί Subscribe on YouTube

We Are Recommending You

β˜…

How to Comment Code in Laravel Blade File?

Read Now β†’
β˜…

How to Export JSON to CSV File using JavaScript/JQuery?

Read Now β†’
β˜…

Laravel 10 Import Export Excel and CSV File Tutorial

Read Now β†’
β˜…

Laravel Download File from URL to Storage Example

Read Now β†’
β˜…

Laravel Seeder from CSV File Example

Read Now β†’
β˜…

Laravel File Manager Tutorial Step by Step

Read Now β†’
β˜…

How to Delete File from Public Folder / Storage Folder in Laravel?

Read Now β†’
β˜…

Laravel Copy File from One Folder to Another Example

Read Now β†’
β˜…

How to Display Image from Storage Folder in Laravel?

Read Now β†’
β˜…

Laravel Validation for Multiple Files in Array Example

Read Now β†’
β˜…

Laravel 11 Merge Multiple PDF Files Example

Read Now β†’
β˜…

How to Get File Size from Storage in Laravel?

Read Now β†’
β˜…

Laravel Storage Dropbox Integration Example

Read Now β†’