Advertisement
Guest User

File upload HTML

a guest
Mar 28th, 2022
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.88 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>GFG</title>
  5. </head>
  6. <body>
  7. <br>
  8. <br>
  9. <form method="POST" enctype="multipart/form-data">
  10.     <div style="width:80%" class="hzcenter">
  11.         <!-- File selection -->
  12.         <input id="upfile" type="file" name="files[]" value="upload" onchange="sub(this)" multiple/>
  13.         <br>
  14.         <br>
  15.     </div>
  16.     <!-- <label class="styled-file-upload hzcenter">
  17.         <input type="file" name="files[]" multiple=""/>
  18.         Choose file(s)
  19.     </label> -->
  20.     <br>
  21.     <div style="width:80%" class="hzcenter">
  22.         <input style="width:100%" class="uploadbutton hzcenter" type="submit" value="Upload">
  23.     </div>
  24. </form>
  25.  
  26. <!--Jquery Cdn -->
  27. <script src="https://code.jquery.com/jquery-3.5.1.js"
  28.         integrity="sha256-QWo7LDvxbWT2tbbQ97B53yJnYU3WhH/C8ycbRAkjPDc="
  29.         crossorigin="anonymous"></script>
  30.  
  31. <script type="text/javascript">
  32.     var files = [];
  33.  
  34.     function sub(obj) {
  35.         if (obj.isDirectory) {
  36.             // document.getElementById("selectedFiles").innerHTML = "true"; //Name[fileName.length - 1];
  37.             console.log("obj is directory")
  38.         } else {
  39.             // Retrieve list
  40.             files = obj.files;
  41.             // Build the table of selected files
  42.             selected_files = "<table style=\"width:100%\"><tr><td style=\"text-align: center\"><b>Selected Files</b></td></tr>";
  43.             for (let i = 0; i < files.length; i++) {
  44.                 selected_files += "<tr><td>" + files[i].name + "</td></tr>";
  45.             }
  46.             selected_files += "</table>";
  47.             // Display them.
  48.             document.getElementById("selectedFilesList").innerHTML = selected_files; //Name[fileName.length - 1];
  49.         }
  50.     }
  51.  
  52.     $(document).on('submit','#upload-form', function(e)
  53.                 {
  54.     e.preventDefault();  // Prevents page reload
  55.     $.ajax({
  56.         type:'POST',
  57.         url:'/',  // Replace with route to POST to
  58.         data:{
  59.             files: files,
  60.             todo:$("#todo").val()
  61.         },
  62.         success:function() // Called when values are successfully submitted
  63.         {
  64.         alert('saved');
  65.         }
  66.     })
  67.     });
  68. </script>
  69.  
  70. </body>
  71. </html>
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement