arakibi arakibi - 1 year ago 74
HTML Question

issue with image validator rules in laravel 4

I have defined this validating rule for a file(image) in laravel 4 .

'image' => 'image|mimes:jpeg,jpg,bmp,png,gif'

And this is my html code:

{{ Form::label('Image of the product') }} {{ Form::file('image') }}

now , I always get 2 errors while uploading an image even If I chose a png, jpg image

The image must be an image.
The image must be a file of type: jpeg, jpg, bmp, png, gif.

this is the update action that includes image upload :

public function update($id)
$product = Product::find($id);
$validator = Validator::make($data = Input::all(), Product::$rules);
return Redirect::back()->withErrors($validator)->withInput();
$old_img = "";
if(isset($data['image']) and !empty($data['image']))

$image = Input::file('image');
$filename = time().'-'.$image->getClientOriginalName();
Image::make($image->getRealPath())->resize(468, 249)->save('public/img/products/'.$filename);

$data['image'] = 'img/products/'.$filename;
$old_img = $product->image;
return Redirect::route('admin.products');

Joe Joe
Answer Source

Ensure that your form is a multipart one by adding

'files' => 'true'

to the config array.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download