Upload pdf file using Laravel 5
Stefan Bogdanescu
Founder & Senior Architect · 2026-06-29
The process of uploading a user-generated file using Laravel 5 is relatively straightforward. Here's how we can create a form that allows users to upload PDF files, store them in the specified folder, and display a success message upon successful submission.
First, let us begin by defining the relevant routes and controller functions for managing the file upload process: 1. Routes: Create a route group with middleware named 'web' which will handle user requests:php
Route::group(['middleware' => ['web']], function() {
// Routes specific to the web interface
});php
Route::post('upload_pdf', 'FileController@store');php
public function store(Request $request) {
// Code to process and store uploaded PDF files goes here.
}php
$file = $request->file('upload_file');php
$filename = time().'_'.str_random(10).'.'.$file->getClientOriginalExtension();
$path = storage_path('app/public/files').'/'.$filename;
$file->move($path, $filename);php
return redirect()->route('dashboard')->with(['success' => 'PDF File Uploaded Successfully']);Inside your blade file (or wherever you choose to display the file details), add the necessary HTML markup:
php
<div class="form-group">
<label for="upload_file" class="control-label col-sm-3"> Uploaded Files</label>
<div class="col-sm-9">
<ul class="list-group">
@foreach($files as $file)
<li class="list-group-item"> <a href="{{ route('download_pdf', ['filename' => $file->name]) }}" target="_blank">{{ $file->name }} ({{ $file->size }})</a> > ⇑</li>
@endforeach
</ul>
</div>
</div>