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

php jquery ajax

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

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

How to Load XML data in jQuery UI autocomplete with PHP

You can load XML data if you have available. In this tutorial, I show how you can load XML file data in jQuery UI autocomplete using AJAX and PHP.

Cannot send array to php via AJAX?

Well I followed&nbsp;<a href="https://stackoverflow.com/questions/9001526/send-array-with-ajax-to-php-script" target="_blank">this</a>&nbsp;question, but cannot send array to php it returns me always empty: