I will give you a simple example of image upload in laravel. you can see image upload in laravel using request method. we will image upload and validation like images, mimes, size, max file upload, etc, So it can protect to upload script.
In this article, we will create a two routes one for get method and one for post method. we created a simple form with file input. So you have to simply select images and then it will upload in the "images" directory of the public folder. So you have to simply follow the bellow step and get image upload in laravel application.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class ImageUploadController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function imageUploadget()
{
return view('imageUpload');
}
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function imageUploadPost(Request $request)
{
$request->validate([
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$imageName = time().'.'.$request->image->extension();
$request->image->move(public_path('images'), $imageName);
return back()
->with('success','You have successfully upload image.')
->with('image',$imageName);
}
}
Read More:
https://www.phpcodingstuff.com/blog/image-upload-in-laravel.html
Top comments (0)