File "code.html"

Full Path: /home/analogde/www/Design/fileman/Fusion/upload_file/0013/code.html
File size: 1.89 KB
MIME-type: text/html
Charset: utf-8


<!--
   https://elevenstechwebtutorials.com/detail/25/how-to-upload-file-using-javascript-and-php
-->

<script>

function uploadData() {

//get input file value
 var content = document.getElementById("file").files;

 if(content.length > 0 ){

    var formData = new FormData();
    formData.append("file", content[0]);
    //formData.append('user', 'person');

    var xhttp = new XMLHttpRequest();

    // ajax file path and Set POST method
    xhttp.open("POST", "fileUpload.php", true);

    // call on request on ready changes state
    xhttp.onreadystatechange = function() {
       if (this.readyState == 4 && this.status == 200) {

         var res = JSON.parse(this.responseText);
         console.log(res.var1); 
         console.log(res.var2); 

         var response = this.responseText;
         if( res.var1 == 1 )
         //if(response == 1)
         {

          

            alert("Upload File Successfully.");

            document.getElementById("affichage").innerHTML = "Attente de 10 s avenc redirection";
            setTimeout(myURL(res.var2), 10000);
            //setTimeout(codingCourse, 10000);
            //window.location.href = "https://www.google.fr";

         }else{
            alert("File Not Uploaded Successfully.");
         }
       }
    };

    // Send request with data
    xhttp.send(formData);

 }else{
    alert("Please Select A File");
 }

}

function codingCourse() {
  console.log("Wait 10 s");
}

function myURL(url) {
         //document.location.href = 'https://www.tutorialspoint.com/index.htm';
         document.location.href = url;
      }

</script>    


<input type="file" name="file" id="file" class="form-control">

<button type="button" class="btn btn-primary btn-lg" onclick="uploadData();" >Upload</button>
<input type="hidden" value="person" name="user">
<p id="affichage"></p>

<?php

?>