
Laravel File Upload with DB Storage
Step 1: Configure Database
Update your .env
file in your Laravel root directory:
Then run:
Step 2: Create File Upload Form (Blade View)
File: resources/views/form.blade.php
Step 3: Create Controller
File: app/Http/Controllers/FormController.php
Step 4: Add Routes
File: routes/web.php
Step 5: Create Migration
Run this command to create the table migration:
Then, update the generated file:
Then run:
Step 6: Run the Project
Visit: http://127.0.0.1:8000/form/new
Summary
Step | Description |
---|---|
.env | Database config |
View | Form and file listing |
Controller | Handles file upload and DB insert |
Route | Routes for form and save |
Migration | Create uplaod_tbl table |
Serve | Launch app with php artisan serve |
Let me know if you'd like to add:
-
File preview/download
-
Delete functionality
-
Storage in public folder instead of local
-
Validation (file types, size)
file_get_contents(C:\Apache24\htdocs\multiple-file-upload\public): failed to open stream: Permission denied
How to fix this ?
error in FormController
Storage::disk('local')->put($folder_name.'/'.$file_name,file_get_contents($photo->getRealPath()));