Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:


every time occur this error even we have set the enctype="multipart/form-data"

Someone, Please help me to resolve this issue.
we are posting our form and controller below.
Please help me to resolve

====Form ==========

<form method="request" action="pupload"  enctype="multipart/form-data">
   @csrf
   <input type="file" name="userfile" id="userfile"  class="form-control">
   <br>
   <button type="submit" class="btn btn-primary">Submit</button>
 </form>


======controller =====

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class PracticeController extends Controller
{
    function index(){
		return view('form');
	}
	
	function upload(Request $request){
		$path=$request->file('userfile')->store('public');
		if($path){
            return "file uploaded successfully";
        }
	}
}


===Route===

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\PracticeController;

/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('/', function () {
    return view('welcome');
});

Route::get('practice',[PracticeController::class,'index']);

Route::get('pupload',[PracticeController::class,'upload']);


What I have tried:

Someone , Please help me to resolve this error.
I'll be very thankfull for this kind act
Posted
Updated 20-Aug-21 6:22am

PHP
$path=$request->file('userfile')->store('public');

The message is telling you that the call to $request->file('userfile') does not return anything. You will need to do some debugging to find out why.
 
Share this answer
 
use Illuminate\Support\File;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900