I've created a form using primary regular HTML (syntax below). When I use the laravel 4 built in function fails(), it works. When I use the laravel 4 built in function passes(). My app is saying no file chosen. My syntax is below, what am I doing wrong? Thanks
// the syntax below won't allow the image to upload. Its giving me an error
$rules = array(
/*'title' => 'required|max:90|min:3'*/
/*'image' => 'required|image|mimes:jpg, jpeg, bmp, png'*/
);
$validator = Validator::make(Input::all(), $rules);
if($validator->passes()){
return Redirect::route('upload-image-post')
->withErrors($validator)
->withInput();
}
// the syntax below will let the image upload
$rules = array(
/*'title' => 'required|max:90|min:3'*/
/*'image' => 'required|image|mimes:jpg, jpeg, bmp, png'*/
);
$validator = Validator::make(Input::all(), $rules);
if($validator->fails()){
return Redirect::route('upload-image-post')
->withErrors($validator)
->withInput();
}
Image upload form
<form action="{{ URL::route('upload-image-post') }}" method="post" enctype="multipart/form-data">
<div class="field">
<label>Title:</label>
<input type="text" name="title"{{ (Input::old('title')) ? ' value="' . e(Input::old('title')) . '"' : '' }}>
@if($errors->has('title'))
{{ $errors->first('title') }}
@endif
</div>
<div class="field">
<label>Select image to upload:</label>
<input type="file" name="image" >
<input type="submit" value="Upload Image" name="submit">
@if($errors->has('image'))
{{ $errors->first('image') }}
@endif
</div>
{{ Form::token() }}
</form>
Did you found your problem? I'm having the same with videos right now with Laravel 5.
For your image rule you can try this instead:
'image' => 'required|image|mimes:jpeg,bmp,png'
Not jpg but jpeg and no spaces after comma.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community