I am developing a WordPress plugin. In that plugin, there is a form with file upload HTML input element. Submitting the form with selecting excel files (.xlsx and xls) does not create $_POST and $_FILES requests.
<input type='file' id='test_upload_pdf' name='test_upload_pdf' required>
JS Handle
jQuery('#test_upload_pdf').bind('change', function() {
var allowedType = ['image/png', 'image/jpg', 'application/pdf'];
if(this.files[0].size < 1600000)
{
if(!(jQuery.inArray(this.files[0].type, allowedType) >= 0))
{
swal("Error", "The file upload is not valid type. Please try with valid file types.", "error");
jQuery('#submit').prop("disabled", true);
}
else{
swal("Success", "The file got uploaded!", "success");
jQuery('#submit').prop("disabled", false);
}
}
else{
swal("Error", "The file is very big in size. Try again with smaller size file.", "error");
jQuery('#submit').prop("disabled", true);
}
});
PHP Handle
var_dump($_GET,$_POST, $_FILES); //$_GET => object, $_POST and $_FILES -> Empty
if ( validateIsSet( $_POST['file_title'] ) && validateIsSet($_FILES['test_upload_pdf']) ){
// logic
}
I bind the input element with JavaScript to detect the changes; it does detect the file upload event but the WordPress does not create $_FILES and $_POST variables and not generate $POST. They are empty. All other file types generate POST request.