Upload images using laravel only

Create basic view

<form action="{{route('upload_file')}}" method="post" enctype="multipart/form-data">
       @csrf
        <p>
            <label for="file">Image</label>
            <input type="file" name="image">
        </p>
        <p>
            <input type="submit" name="upload" value="Upload">
        </p>
    </form>

Use controller for file upload

public function upload_file(Request $request){
        $imageName = time().'.'.$request->image->extension();

        // Public Folder ===> public/storage/images
        $path=$request->image->move(public_path('storage/images'), $imageName);
        echo $path;
    }

Use routes for file upload

Route::get("/upload",[DashboardController::class,'upload'])->name("upload");
Route::post("/upload_file",[DashboardController::class,'upload_file'])->name("upload_file");

 

© 2016 - 2022, All Rights are Reserved.