简体   繁体   中英

File is not being uploaded in Laravel

This is very similar to a question I asked recently, which I have since deleted, but I have a better understanding of the issue I'm facing now and believe I could ask a more clear question.

I am creating a file upload application. I am limiting it to only .dem files, which are quite uncommon. I have added enctype="multipart/form-data" to support my file upload, and I have correctly named everything. When I submit my file, it does not seem to be received by the controller.

Here is my code:

Blade

<form action="{{ route('upload') }}" method="POST" enctype="multipart/form-data" class="form">
    @csrf
    <label for="demo" id="drop" class="drop">
         <p>Drag demos here <br>or <span style="color:#2b66cc;">browse</span></p>
    </label>
    <input id="demo" type="file" name="demo" multiple accept=".dem"></input>
    <div id="list" style="cursor:default;" class="ui animated list"></div>
    <button id="submit" class="ui primary fluid button" disabled type="submit">Upload</button><br>
</form>

Route

Route::post('/', 'App\Http\Controllers\UploadController@store')->name('upload');

Controller

class UploadController extends Controller
{
    public function store(Request $request)
    {

        dd($request->file());
        
    }
}

All I'm doing here is just trying to receive the file.

When I run this code and upload a file through the form, $request-file() returns an empty array. This indicates to me that my file never actually reaches the controller for some reason beyond me.

Any help would be greatly appreciated.

 <input id="demo" type="file" name="demo[]" multiple accept=".dem">

当您在 INPUT 标签中上传多个文件时 INPUT 标签进入数组

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM