I Upload MS Word Document (.docx) in Laravel Using <input type="file">
My MS Word File is Automatically Converted as (.file) Format While Storing in storage/app/public
How to Again Download Same (.docx) Formatted File?
ApplicationController.php
function create(Request $req) { $application = new Application; $application->opening_id = $req->input('opening_id'); $application->first_name = $req->input('first_name'); $application->last_name = $req->input('last_name'); $application->gender = $req->input('gender'); $application->dob = $req->input('dob'); $application->address = $req->input('address'); $application->mobile = $req->input('mobile'); $application->email = $req->input('email'); $path = $req->file('resume')->store('public/resumes'); $path = trim($path,"public/"); $application->resume = $path; $application->application_status = $req->input('application_status'); $application->save(); return redirect('admin/view-applications'); }
Add-Application.php
<div class="input-group"> <div class="custom-file"> <input type="file" class="custom-file-input" name="resume" required> <label class="custom-file-label" for="exampleInputFile">Choose Resume</label> </div>
Image: Saved File Properties Window
Advertisement
Answer
Change your saving part and it’ll work.
You need to extract original name of file which and pass it to store
method which will prevent the store
method from giving it automatic name, Try the below code and let me know
function create(Request $req){ $application = new Application; $application->opening_id = $req->input('opening_id'); $application->first_name = $req->input('first_name'); $application->last_name = $req->input('last_name'); $application->gender = $req->input('gender'); $application->dob = $req->input('dob'); $application->address = $req->input('address'); $application->mobile = $req->input('mobile'); $application->email = $req->input('email'); $filename = $req->file('resume')->getClientOriginalName(); $path = $req->file('resume')->storeAs('public/resumes',$fileName); $path = trim($path,"public/"); $application->resume = $path; $application->application_status = $req->input('application_status'); $application->save(); return redirect('admin/view-applications'); }