Level 122
Look at validating arrays https://laravel.com/docs/5.5/validation#validating-arrays
and validating image https://laravel.com/docs/5.5/validation#rule-image
Hi,
I am writing Program on Uploading Image to the database. the written programs works when i upload image to the database and it gets saved to the images folder which is under public.
How to add the Validation for the Image input not to add any other files only images in laravel
in the controller i have written as below
public function saveImage(Request $request){
$files = Input::file('images');
$file_count = count($files);
$uploadcount = 0;
foreach ($files as $file) {
$destinationPath = 'images';
$filename = $file->getClientOriginalName();
$file->move($destinationPath,$filename);
$uploadcount ++;
$file->getClientOriginalExtension();
$entry = new \App\image();
$entry->mime = $file->getClientMimeType();
$entry->filename = $filename;
$entry->save();
}
return redirect('/image/upload')->with("success","Uploaded Sucessfully");
}
in the blade file
<div class="col-sm-10 well-lg">
<div class="row">
<div class="container-fluid">
<div class="form-group">
<h2>Image Upload</h2>
{!! Form::open(array('url'=>'/image/update','method'=>'POST', 'files'=>true)) !!}
{!! Form::file('images[]', array('multiple'=>true)) !!}
<p>{!!$errors->first('filename')!!}</p>
@if(Session::has('error'))
<p>{!! Session::get('error') !!}</p>
@endif
{!! Form::submit('Submit', array('class'=>'btn btn-lg btn-primary col-md-4')) !!}
{!! Form::close() !!}
</div>
</div>
</div>
</div>
in the web.php file
Route::get('/image/upload','ImageuploadController@getImage');
Route::post('/image/update','ImageuploadController@saveImage');
Please or to participate in this conversation.