'Input File Size & Type
I'm new at Laravel.
How can I limit the file size to 5mb and file type in Controller?
public function add_presentation_detail(Request $request){
$start_date = $request->start_date;
$input_file = $request->file;
$nik = Sentinel::getUser()->nik;
$data = AccelerateMentee::select(
'accelerate_mentee.*',
'accelerate_rotation.start_date',
'accelerate_rotation.id as id_rotation'
)
->leftJoin('accelerate_rotation', 'accelerate_rotation.id_mentee', '=', 'accelerate_mentee.id')
->where([
['accelerate_mentee.nik', '=', $nik],
['accelerate_rotation.status', '<>', 'approved']
])
->first();
if (!empty($request->file) && $request->hasFile('file')) {
$filename = $input_file->getClientOriginalName();
$new_filename = "presentation_" . "-" . $filename;
$upload_file = $input_file->storeAs('public/accelerate/',$new_filename);
} else {
$new_filename = null;
}
$update = AccelerateRotation::where('id', '=', $data->id_rotation)
->update([
'status' => 'submitted',
'panel_time_start' => $start_date,
'file' => $new_filename,
]);
return redirect()->back();
}
Hope u guys answer my question, I'm really confused. Thank u so much!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
