How to save 'multipart/form-data' (picture, pdf, and etc.) to mysql database mediumblob via jquery?

How to save 'multipart/form-data' (picture, pdf, and etc.) to mysql database mediumblob via jquery?

I am building an assessment tool. The logic is:

I am building an assessment tool. The logic is:

  1. In each question, once I click 'Upload/View Files', it will pop up a modal;
  2. In the modal, there is a section you can select pic/document/video to upload. The code is as:Html code
  3. Once you click submit, it will trigger jquery as below:
$(document).ready(function(){   
    $('#upload_file_attachment').submit(function(event){
        event.preventDefault();
        var formData = new FormData($(this)[0]);
        $.ajax({
            url: "ajax/upload-attachment.ajax.php",
            type: "POST",
            data: formData,
            async: false,
            cache: false,
            contentType: false, 
            processData: false,
            'success': function(data){
                            $('#upload_success_msg').fadeIn().html(data);
                            setTimeout(function(){
                                $('#upload_success_msg').fadeOut("Slow");
                            },5000);
                        }
        }); //End of ajax


})//End of submit

})

  1. And the following is ajax php code:
require_once '../php-includes/connect.inc.php';
global $db;
$assess_id=$_POST['assess_id'];
$quest_ref=$_POST['quest_ref'];
$email=$_POST['email'];
$type=$_POST['type'];

if($type=="file"){ $file=$_FILES["file"]; $fileName=$file["name"][0]; if(empty($fileName)){ echo "No File Selected"; return; } $fileType=$file["type"][0]; $fileData=$file["tmp_name"][0];

mysqli_query($db, "INSERT INTO files VALUES('$assess_id','$quest_ref','$fileName','$fileType','$fileData', NOW(), '$email', '')"); echo "Success";

}

  1. However, when I check database after uploading the file, it only upload the name like 'C:xampp mpphpFE6F.tmp' into the blob, apparently the $fileData is not correct. Could you please help me how i can do this?

Thanks

Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

jQuery ajax get request method example

### jQuery Ajax Get Request Method Example This article is originally published at [https://www.tutsmake.com/jquery-api-ajax-get-method-example/](https://www.tutsmake.com/jquery-api-ajax-get-method-example/...

How To Create Chat App in PHP Using Ajax and JQuery

In this tutorial, you'll learn how to create chat system in PHP using Ajax and JQuery

Ajax (jQuery) PHP Script // move_uploaded_file-problem

I'm working on a&nbsp;<strong>gallery-upload</strong>-function with