Hi guys
I need to upload a pdf file view a form and store it in a public/certificate, also store the id into a db field certificate.The code execute successfull but what happens it just create a folder with filename.pdf and inside it i see .tmp. No pdf file which i uploaded.
my controller
public function store(Request $request)
{
//validate the received data
$request->validate([
'enrol_id'=>'required',
'enrol_code'=>'required',
'enrol_mode'=>'required',
'upload_file' => "required|mimetypes:application/pdf|max:10000",
'enrol_date' => 'date_format:Y-m-d|before:today|after:2020-04-01'
]);
$uniqueFileName =$request->get('enrol_id').'.'.rand(11111111, 99999999). '.' . $request->file('upload_file')->getClientOriginalExtension();
$successUpload=$request->file('upload_file')->move(public_path('certificates/') . $uniqueFileName);
if($successUpload){
$enrollments=new Enrollment();
$enrollments->enrol_id=$request->get('enrol_id');
$enrollments->enrol_code=$request->get('enrol_code');
$enrollments->enrol_mode=$request->get('enrol_mode');
$enrollments->enrol_date=$request->get('enrol_date');
$enrollments->certificate=$uniqueFileName;
$enrollments->save();
}
return redirect('/enrollments')->with('success','Contact enrolled!');
}
my view
<div class="form-group">
<label for="upload_file" class="control-label col-sm-3">Upload File</label>
<div class="col-sm-9">
<input class="form-control" type="file" name="upload_file" id="upload_file">
</div>
</div>
into db the filename get stored. but can't see the actual pdf uploaded hence cant download
<td>
<a href="{{URL::to('/')}}/certificates/{{$value['certificate']}}" target="_blank">
<button class="btn"><i class="fa fa-download"></i> {{$value['certificate']}}</button>
</a>
</td>
hello can you use store instead of move ? for this you need to link storage folder with this command php artisan storage:link after that use the store with the request object like this :
the first parameter is what folder you will store the pdf into your project storage/file.
the second parameter is the option (what folder you will use to store all your upload) in general i store the folder in my public folder.
you can save the path like this on the database if you want to retreive them data.