Laravel 4-没有可用的猜测器问题 [英] Laravel 4 - no guessers available issue

查看:111
本文介绍了Laravel 4-没有可用的猜测器问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:LogicException:无法尝试猜测mime类型,因为没有可用的猜测器(您是否启用了php_fileinfo扩展名?),而尝试上载图像时. 我启用了php_fileinfo扩展名,还重新启动了Wamp Web服务器,但仍然无法解决此问题.我想念什么?谢谢

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

下面是我的代码:

型号:Product.php

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');
}

}

控制器:ProductsController.php

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();
}

视图:Index.blade.php

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() }}

推荐答案

我认为这是WAMP Web服务器的错误.我切换到XAMPP Web服务器,它工作正常.

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

非常感谢.

这篇关于Laravel 4-没有可用的猜测器问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆