'Unable to guess the mime type as no guessers are available Laravel 5.2
So I'm getting this when I want to submit my form:
Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?)
I have enabled in php.ini - php_fileinfo extension
. I also restarted my localhost server.
This is my rule: 'img_1' => 'required|mimes:png,gif,jpeg',
This is what I get when I submit form:
at MimeTypeGuesser->guess('C:\xampp\tmp\php2490.tmp') in File.php line 79
This is how I uploading image:
public function storeAuction(AuctionSubmitRequest $request)
{
$product = Product::create($request->all());
if(Input::hasfile('img_1'))
{
$request->file('img_1')->move(public_path('images'), $request->file('img_1')->getClientOriginalName());
$product->img_1 = 'images' . $request->file('img_1')->getClientOriginalName();
}
$product->user_id = Auth::user()->id;
$product->save();
return redirect('/');
}
Solution 1:[1]
You have to comment out the following line from your php.ini and then restart your apache
extension=php_fileinfo.dll
Solution 2:[2]
You can "hack" this problem by creating an Enum class that will check if mimes is accurate
<?php
namespace App\Support\Enum;
enum ImageExtension: string {
case Png = 'png';
case Jpg = 'jpg';
case Jpeg = 'jpeg';
/**
* Return all values as array
*
* @return array
*/
public static function values()
{
return array_map(
fn(ImageExtension $imageExtension) => $imageExtension->value,
self::cases()
);
}
}
Then in your request just check it like this
['image', 'mimes:' . implode(',', ImageExtension::values()), 'max:10000'],
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Muminur Rahman |
Solution 2 | dz0nika |