Laravel Get File Mime Type from Storage Example
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...
Hardik Savani
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I live in India and I love to write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery, Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.
We are Recommending you
- How to Comment Code in Laravel Blade File?
- How to Export JSON to CSV File using JavaScript/JQuery?
- Laravel 10 Import Export Excel and CSV File Tutorial
- Laravel Download File from URL to Storage Example
- Laravel Seeder from CSV File Example
- Laravel File Manager Tutorial Step by Step
- How to Delete File from Public Folder / Storage Folder in Laravel?
- Laravel Copy File from One Folder to Another Example
- How to Display Image from Storage Folder in Laravel?
- Laravel Validation for Multiple Files in Array Example
- Laravel 11 Merge Multiple PDF Files Example
- How to Get File Size from Storage in Laravel?
- Laravel Storage Dropbox Integration Example