othmannl's avatar

CANNOT UPLOAD FILE LARAVEL

I want to upload a file in an edit page with this code

This is the HTML

<input id="attachment" type="file"
                               class="form-control @error('attachment') is-invalid @enderror"
                               name="attachment" value="{{ old('attachment') }}" required
                               autocomplete="attachment" autofocus>

And in the controller this

 if ($request->hasFile('attachment')) {
            $filenameWithExt = $request->file('attachment')->getClientOriginalExtension();
            $filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
            $extension = $request->file('attachment')->getClientOriginalExtension();
            $fileNameToStore = $filename . '_' . time() . '.' . $extension;
            $request->file('attachment')->storeAs('storage/files', $fileNameToStore);

        } else {
            $fileNameToStore = 'No File';
        }

BUt when I submit the page, it stores with No File, so I cannot upload and if I Dump and Die the request is see the filename. Help me

0 likes
1 reply
jlrdw's avatar
jlrdw
Best Answer
Level 75

Do you have enctype="multipart/form-data

1 like

Please or to participate in this conversation.