If you have an internal server error, it's likely not a validation failure, but something else. Have you checked your server log to see what the problem is?
Dec 4, 2018
5
Level 1
validating an array of files sent by ajax
hello, I've got this ajax request, I tried several ways to validate photo array, but every time I got an internal server error
let data = new FormData();
data.append('text', $('#text').val());
data.append('photos', uploaded_files);
// uploaded_files is an array of images
$.ajax({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
url: '/profile/newPost',
method: 'POST',
data: data,
contentType: false,
processData: false,
success: function(response){
console.log("response: ",response);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error: " + textStatus + ' : ' + errorThrown);
}
this is my controller, but it doesn't work for me, don't know why
$data = $request->all();
$validator = Validator::make(
$data, [
'photos.*' => 'required|mimes:jpg,jpeg,png,bmp|max:20000'
],[
'photos.*.required' => 'Please upload an image',
'photos.*.mimes' => 'Only jpeg,png and bmp images are allowed',
'photos.*.max' => 'Sorry! Maximum allowed size for an image is 20MB',
]
);
if ($validator->fails()) {
// Validation error..
}
could anyone help me please
Level 51
Please or to participate in this conversation.