Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Laravel 4 - no guessers available issue

I get this error: LogicException: Unable to guess the mime type as no guessers are available (Did you enable the php_fileinfo extension?) while trying to upload an image. I have enabled the php_fileinfo extension and also restarted the Wamp web server but I still unable to solve this. What am I missing? Thanks

Below are my codes:

Models: Product.php

class Product extends Eloquent {

protected $fillable = array('category_id', 'title', 'description', 'price', 'availability', 'image');

public static $rules = array(
    'category_id'=>'required|integer',
    'title'=>'required|min:2',
    'description'=>'required|min:20',
    'price'=>'required|numeric',
    'availability'=>'integer',
    'image'=>'required|image|mimes:jpeg,jpg,bmp,png,gif|max:3000',
);

public function category() {
    return $this->belongsTo('Category');
}

}

Controllers: ProductsController.php

 public function postCreate() {
    $validator = Validator::make(Input::all(), Product::$rules);

    if($validator->passes()) {
        $product = new Product;
        $product->category_id = Input::get('category_id');
        $product->title = Input::get('title');
        $product->description = Input::get('description');
        $product->price = Input::get('price');

        $image = Input::file('image');
        $filename = date('Y-m-d-H:i:s')."-".$image->getClientOriginalName();
        Image::make($image->getRealPath())->resize(468,249)->save('public/img/products/'.$filename);
        $product->image = 'img/products/'.$filename;
        $product->save();

        return Redirect::to('admin/products/index')
            ->with('message', 'Product Created');
    }

    return Redirect::to('admin/products/index')
        ->with('message', 'Something went wrong')
        ->withErrors($validator)
        ->WithInput();
}

Views: Index.blade.php

  {{ Form::open(array('url'=>'admin/products/create', 'files'=>true)) }}
    <p>
        {{ Form::label('category_id', 'Category') }}
        {{ Form::select('category_id', $categories) }}
    </p>
    <p>
        {{ Form::label('title') }}
        {{ Form::text('title') }}
    </p>
    <p>
        {{ Form::label('description') }}
        {{ Form::textarea('description') }}
    </p>
    <p>
        {{ Form::label('price') }}
        {{ Form::text('price', null, array('class'=>'form-price')) }}
    </p>
    <p>
        {{ Form::label('image', 'Choose an image') }}
        {{ Form::file('image') }}
    </p>
    {{ Form::submit('Create Product', array('class'=>'secondary-cart-btn')) }}
    {{ Form::close() }}
like image 904
user3227412 Avatar asked Apr 14 '14 16:04

user3227412


3 Answers

uncomment this line in php.ini into php folder.

extension=php_fileinfo.dll

and restart the server(enter 'php artisan serve' again). This way will works!

like image 77
Claudivan Avatar answered Nov 03 '22 21:11

Claudivan


Open php.ini file and you can find ;extension=php_fileinfo.dll remove the semi-coloumn to extension=php_fileinfo.dll will work perfectly then restart the your apache server or xampp ,wampp whatever environment you are using

like image 44
ujwal dhakal Avatar answered Nov 03 '22 22:11

ujwal dhakal


I think is the WAMP Web Server's Bug. I switched to XAMPP Web Server and it works fine.

Thanks alot by the way.

like image 27
user3227412 Avatar answered Nov 03 '22 20:11

user3227412