Untitled

 avatar
unknown
php
a year ago
846 B
7
Indexable
<?php

   namespace App\Http\Controllers;

   use Illuminate\Http\Request;
   use App\Models\File;

   class FileUploadController extends Controller
   {
       public function showUploadForm()
       {
           return view('upload');
       }

       public function uploadFile(Request $request)
       {
           $request->validate([
               'file' => 'required|file|mimes:jpg,png,pdf,docx|max:2048',
           ]);

           if ($request->file('file')) {
               $filePath = $request->file('file')->store('uploads', 'public');

               $file = new File();
               $file->file_path = $filePath;
               $file->save();

               return back()->with('success', 'File uploaded successfully.');
           }

           return back()->with('error', 'Please select a file to upload.');
       }
   }


Editor is loading...
Leave a Comment