Topic: File Upload
NeoXP free asked 1 year ago
Hi im trying to use the fileuploader plugin in laravel, i used the snippet and it works, but i was wondering how can i actually upload the file ? Sorry if this is a stupid question, but i tried googling and didnt find anything suitable for mdb
PS: I also tried to provide my div here, but it caused a bug :D so i editet it again
Mateusz Lazaru staff answered 1 year ago
MDB File Upload Plugin works just like a regular input
with type='file'
You'll just need to add it to the form, allow the user submitting it to the server and handle it on the server-side.
This is a code I've found for you and modified to include File Upload Plugin.
Create a form in your blade template with an input element of type file:
<form action="{{ route('file.upload') }}" method="POST" enctype="multipart/form-data"> @csrf <input type="file" id="input-file-now" class="file-upload-input" data-mdb-file-upload="file-upload" name='file' /> <button type="submit">Upload</button> </form>
Create a route in your web.php file that maps to a controller method that handles the file upload:
Route::post('/file/upload', 'FileController@upload')->name('file.upload');
Create a controller called FileController with a method called upload that will handle the file upload:
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class FileController extends Controller { public function upload(Request $request) { // Validate the uploaded file $request->validate([ 'file' => 'required|file|mimes:pdf,doc,docx|max:2048' ]); // Get the uploaded file $file = $request->file('file'); // Save the file to a storage location $file->store('public/uploads'); // Return a response return response()->json(['message' => 'File uploaded successfully']); } }
FREE CONSULTATION
Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.
Answered
- ForumUser: Free
- Premium support: No
- Technology: MDB Standard
- MDB Version: MDB5 6.2.0
- Device: Any
- Browser: Chrome
- OS: Windows
- Provided sample code: No
- Provided link: No
Ameliajhnson free commented 1 year ago
File upload refers to the process of transferring a file from a local system to a remote system, typically via the Internet. It can be used to send documents, photos, videos, and other types of files. The file upload process usually involves selecting a file, clicking the upload button, and waiting for the upload to complete. Depending on the size of the file, the upload can take anywhere from a few seconds to several minutes.
NeoXP free commented 1 year ago
thanks, but i know the definition of a file upload :) i was wondering about the code for laravel