试图上传图片 - 无法猜测mime类型,因为没有可用的猜测器(你启用了php_fileinfo扩展吗?)

时间:2018-02-18 19:16:10

标签: laravel laravel-5 file-upload

上传图片时出现此错误

无法猜测mime类型,因为没有可用的猜测器(你启用了php_fileinfo扩展吗?)

我已取消注释行extension = php_fileinfo.dll(这不起作用) 但错误仍然存​​在。这是我的控制器,用于处理表单的位置

表单控制器     

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests\UploadRequest;
use App\PropertyAdvert;
use App\PropertyAdvertPhotos;

class AdvertisementController extends Controller
{
    public function index(){
      return view('pages/Advert/create');
    }

    public function store(Request $request, UploadRequest $request1){
      $Advert = new PropertyAdvert();

      $Advert::create(
        [
          "address" => $request->address,
          "county" => $request->county,
          "town" => $request->town,
          "type" => $request->type,
          "rent" => $request->rent,
          "date" => $request->date,
          "bedrooms" => $request->bedrooms,
          "bathrooms" => $request->bathrooms,
          "furnished" => $request->furnished,
          "description" => $request->description
]);
          foreach($request1->photos as $photo){
            $filename = $photo->store('photos');
            PropertyAdvertPhotos::create([
              'propertyadvert_id' => $Advert->id,
              'filename' => $filename
            ]);
          }

      return "Success. Your adveret has been published";
    }
}

上传请求

<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UploadRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'name' => 'required'
        ];
        $photos = count($this->input('photos'));
        foreach(range(0, $photos) as $index) {
            $rules['photos.' . $index] = 'image|mimes:jpeg,bmp,png|max:2000';
        }

        return $rules;
    }
}

0 个答案:

没有答案