For an order system I made using Laravel users are able to upload files related to an order. These are send via an ajax call and processed by a Laravel controller, after which the page is reloaded.
Now the problem which I’m having is that at a certain point, after an user has uploaded some files in a short period of time and they want to upload another file, they are greeded with an ERR_CONNECTION_TIME_OUT. Note that the file is uploaded succesfully each time.
I checked the Apache and Laravel error logs and there is nothing relevant there. I also checked the php.ini upload limits and execution times and I don’t think they cause any issue as they are set to 128Mb (they only upload PDFs), and 30sec respectively.
Am I missing something here?
Ajax:
$("#upload").on( "click", function() {
var files = $('input[name=global_file]')[0].files;
var fd = new FormData();
fd.append('global_file',files[0]);
fd.append('tm_num', {{ $order['tm_num'] }});
$.ajax({
type: "POST",
url: '/admin/order/upload',
data: fd,
processData: false,
contentType: false,
success: function () {
window.location.reload();
}
});
});
Controller.php:
public function UploadOrderFile(Request $request)
{
$data = $request->all();
$file = $request->file('global_file');
$basepath = base_path();
$destinationPath = $basepath.'/orders/'.$data['tm_num'];
$fileName = $file->getClientOriginalName();
$file->move($destinationPath,$fileName);
return;
}
2
Answers
On ajax headers, need to set the csrf token to access the request.