To upload files you must set this encryption in your form :
enctype="multipart/form-data"
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm having a hard time getting file uploads to work in Laravel 5. When I try to get the file from the request and dump it, it returns "null".
Response:
null
array (size=3)
'_token' => string 'lYgV8SPSOrcU7bYhQPL18Sggmvn7FGylD3AHpaL2' (length=40)
'name' => string 'Test' (length=4)
'template_file' => string '2-110P61AH80-L.jpg' (length=18)
Controller:
/**
* Process the uploaded form.
*
* @Post("form/create")
*
* @return Response
*/
public function postCreate(FormCreateRequest $request)
{
var_dump($request->file('template_file'));
var_dump($request->all());
return 'Posted';
}
Request:
class FormCreateRequest extends Request {
protected $dontFlash = ['template_file'];
/**
* Get the validation rules that apply to the request.
*
* @todo Validate mime-types.
*
* @return array
*/
public function rules()
{
return [
'name' => 'required',
'template_file' => 'required|max:1024',
'javascript_file' => 'max:1024',
'css_file' => 'max:1024'
];
}
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
}
@extends('app')
@section('content')
<div class="container">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Create a new form</div>
<div class="panel-body">
@include('partials.errors.basic')
<form class="form-horizontal" role="form" method="POST" action="/form/create">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<label for="name" class="col-sm-3 control-label">Name</label>
<div class="col-sm-6">
<input type="text" id="name" name="name" class="form-control" placeholder="Name" value="{{ old('name') }}">
</div>
</div>
<div class="form-group">
<label for="email" class="col-sm-3 control-label">Template</label>
<div class="col-sm-6">
<input type="file" id="template_file" name="template_file">
</div>
</div>
<div class="form-group">
<label for="password" class="col-sm-3 control-label">CSS</label>
<div class="col-sm-6">
<input type="file" id="css_file" name="css_file">
</div>
</div>
<div class="form-group">
<label for="password_confirmation" class="col-sm-3 control-label">Javascript</label>
<div class="col-sm-6">
<input type="file" id="js_file" name="js_file">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-3 col-sm-3">
<button type="submit" class="btn btn-primary"><i class="fa fa-btn fa-cloud-upload"></i>Create Form</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
@stop
Is this a bug or am I just missing something very obvious?
Please or to participate in this conversation.