I am working on a project where the requirement is to upload a PDF file to the server in file format, e.g. /home/xyz/proect_dir/upload/file_name.pdf, and store the file path to MySQL Database. I am uploading a PDF file using PHP & AJAX. I am getting a following error.
Notice: Undefined index: uploaded_pdf
Here is my code:
upload.html
<form action="#" method="post" id="frm_upload_pdf" enctype="multipart/form-data">
    <input type="file" name="uploaded_pdf" id="uploaded_pdf" accept="application/pdf" class="upload" />
    <button type="submit" id="btnUploadPaper">Save</button>       
</form>
upload.js
$('#frm_upload_pdf').validate({
    rules: {
        uploaded_pdf: { required: true }
    },
    messages: {
        uploaded_pdf: { required: "Select pdf file" }
    },
    errorPlacement: function(error, element) {
        error.insertAfter(element);
    },
    submitHandler: function() {
        uploadPDF();
    }
});
function uploadPDF() {
    $.ajax({
        url: 'upload_processor.php',
        type: 'POST',
        data: $('#frm_upload_pdf').serialize(),
        success: function (data) {
            alert(data);
        }
    });
}
upload_processor.php
public function uploadPaper() {
    $fileName   = $_FILES['uploaded_pdf']['name'];
    $temp_name  = $_FILES['uploaded_pdf']['tmp_name'];
    if (isset($fileName)) {
        if (!empty($fileName)) {
            $fileType = pathinfo(FILE_UPLOAD_ROOT.$fileName, PATHINFO_EXTENSION);
            $allowTypes = array('pdf');
            if (in_array($fileType, $allowTypes, true)) {
                //upload file to server
                return move_uploaded_file($temp_name, FILE_UPLOAD_ROOT.$fileName) ? true : false;
            }
            return false;
        }
        return false;
    }
    return false;
}
While debugging I found that ajax does not post the file data as $_FILES, hence it is giving above error of undefined index. Any idea why it is not posting the file data as $_FILES or am I missing anything here.
 
    