There are loads of upload tutorials available. PDF is no different to any other type of upload.
How to upload pdf file in laravel
Hi how can I upload pdf file in laravel?
I upload image but when I try for pdf don't work
'don't work'
Can't help you there I'm afraid. Try googling 'don't work' - see what you get
if($request->hasFile('file')){
$filenameWithExt = $request->file('file')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('file')->getClientOriginalExtension();
$fileNameToStore = $filename.'-'.time().'.'.$extension;
$path = $request->file('file')->storeAs('public/file', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
// Create
$monogeraf = new Monogeraf;
$monogeraf->thesis_code = $request->input('thesis_code');
$monogeraf->student_code = $request->input('student_code');
$monogeraf->title = $request->input('title');
$monogeraf->author = $request->input('author');
$monogeraf->supervisor = $request->input('supervisor');
$monogeraf->advisor = $request->input('advisor');
$monogeraf->department = $request->input('department');
$monogeraf->date_defance = $request->input('date_defance');
$monogeraf->file = $fileNameToStore;
$monogeraf->save();
if($monogeraf){
return redirect()->route('monogerafs.index', ['monogeraf'=>$monogeraf->id])
->with('success', 'Monogeraf Create successfully');
}
return back()->withInput();
this is my source.
How far does it get through your code?
What errors do you see?
Do you end up with 'noimage.jpg' written the the database?
yes when I upload pdf file runs else how can I solve that?
so request does not have 'file'
We would need to see the form to help there
can you help me what shoud I do?
you can examine the request object dd($request) and see if it contains your file, and you can post your upload form here
Do you have enctype="multipart/form-data" on your form element?
<form action="/your-url" method="post" enctype="multipart/form-data">
</form>
Yes I add enctype="multipart/form-data" in my form
Please or to participate in this conversation.