Try to search your question here, if you can't find : Ask Any Question Now ?

how to save an input image in a database with a longblob column?

HomeCategory: stackoverflowhow to save an input image in a database with a longblob column?
Avatarpushpa asked 2 weeks ago

I have a file type input. I want the photo that is inserted in the input to be sent to the db and saved. I wrote some code that according to logic should work. but I do not know why it does not work. where am I wrong? the column photo is a longblob type


 <label for="">img</label>
 <input type="file"  id="immagine" >


 function values(a){

  if (a.length>1){
   var img;

   const fr = new FileReader();
   fr.onload = () => {
    // It worked
     img = fr.result;

       var params= "V1="+a[2]+"& V2="+a[3]+"& V3="+a[4]+"& V4="+a[5]+"& V5="+a[6]+"& V6="+a[7]+"& V7="+a[8]+"& V8="+a[9]+"& V9="+a[10]+"& V10="+a[11]+"& V11="+a[12]+"& V12="+a[13]+"& V13="+a[14]+"& V14="+a[15]+"& img="+img;

       var xhttp = new XMLHttpRequest();
       xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {

       };"POST", "./server/AggiuntaBhk.php", true);
       xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
        xhttp.send( params);

    // ...use the array here...

       fr.onerror = () => {
          // The read failed, handle/report it
            document.getElementById("a").innerHTML= "noo";





 include("../../connessione_db/db_con.php"); // Include il file di connessione al database

 $queryInput="INSERT INTO bhk (Metrica1,Metrica2,Metrica3,Metrica4,Metrica5,Metrica6,Metrica7,Metrica8,Metrica9,Metrica10,Metrica11,Metrica12,Metrica13,Data,Puntoz,Paziente,Foto) VALUES ('$v1','$v2','$v3','$v4','$v5','$v6','$v7','$v8','$v9','$v10','$v11','$v12','$v13','2014-01-01','$v14','BVNVCN97L18C983O','$foto')";

 $queryI = mysqli_query($connessione_al_server,$queryInput);

after query to display

            echo '<img id="imgcaricata" class="mySlides" 
             src="data:image/jpeg;base64,'.base64_encode( $foto["Foto"] 
             style="height:auto; width:auto;max-width:500px; margin-top:55px;" />';

I also tried with until8Array and FileReader.readAsArrayBuffer() in the db I have the correct file but does not display anything. I can only see the image if I insert the image directly in the db using the browse option. am I wrong to store or display?

1 Answers
Best Answer
AvatarMikhail answered 2 weeks ago
Your Answer

20 + 20 =

Popular Tags

WP Facebook Auto Publish Powered By :