How to upload images using Laravel to your public folder
Here is a simple tutorial to quickly upload images to the public folder on your site.>Blade File
<form method="post" id="formImgInp" action="(RouteName)" enctype="multipart/form-data">
<input type="hidden" name="_token" value="(CSRF Function)"/>
<input type="file" name="image" id="image"/>
<input type="submit"/>
</form>
web.php
Route::post('fileUpload', [ 'as' =>'image.add', 'uses' => 'HomeController@fileUpload' ]);
Home Controller
public function fileUpload(Request $request) { $image = $request->file('image'); $input['imagename'] = time() . '.' . $image->getClientOriginalExtension(); $destinationPath = public_path('/images'); $image->move($destinationPath, $input['imagename']); }
This will save your images to public/images. Simple!
Categories: Posts