Tôi nhận được lỗi này: LogicException: Không thể đoán loại mime vì không có người đoán nào (Bạn đã bật phần mở rộng php_fileinfo?) Trong khi cố gắng tải lên một hình ảnh. Tôi đã bật phần mở rộng php_fileinfo và cũng khởi động lại máy chủ web Wamp nhưng tôi vẫn không thể giải quyết vấn đề này. Tôi đang thiếu gì? Cảm ơnLaravel 4 - không có dự đoán nào có vấn đề
Dưới đây là mã của tôi:
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');
}
}
Bộ xử lý: 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();
}
Xem: 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() }}
cố gắng thay đổi giới hạn tải lên tệp trong tệp cấu hình php của bạn – phoops
@ edvinas.me Giới hạn kích thước tệp bạn đã đề cập là upload_max_filesize? Tôi đặt nó thành giá trị lớn upload_max_filesize = 200M nhưng vẫn không thể giải quyết vấn đề này. Loại kỳ lạ. – user3227412
Bạn có đặt số lần trong mã của mình không? như thế này: ''file' => 'mimes: jpeg, bmp, png | max: 3000''. Thật khó để cung cấp thêm bất kỳ đề xuất nào mà không thấy mã. – phoops