Advertisement
Kyfx

Index.php [upload a file using JQuery]

Apr 6th, 2015
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery File Upload Example</title>
  6.  
  7. <!-- Bootstrap CSS Toolkit styles -->
  8. <link rel="stylesheet" href="css/bootstrap.min.css">
  9. <link rel="stylesheet" href="css/styles.css">
  10. </head>
  11.  
  12. <body>
  13. <div class="container">
  14. <!-- Button to select & upload files -->
  15. <span class="btn btn-success fileinput-button">
  16. <span>Select files...</span>
  17. <!-- The file input field used as target for the file upload widget -->
  18. <input id="fileupload" type="file" name="files[]" multiple>
  19. </span>
  20.  
  21.  
  22. <!-- The global progress bar -->
  23. <p>Upload progress</p>
  24. <div id="progress" class="progress progress-success progress-striped">
  25. <div class="bar"></div>
  26. </div>
  27.  
  28.  
  29.  
  30. <!-- The list of files uploaded -->
  31. <p>Files uploaded:</p>
  32. <ul id="files"></ul>
  33.  
  34.  
  35.  
  36. <!-- Load jQuery and the necessary widget JS files to enable file upload -->
  37. <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  38. <script src="js/jquery.ui.widget.js"></script>
  39. <script src="js/jquery.iframe-transport.js"></script>
  40. <script src="js/jquery.fileupload.js"></script>
  41.  
  42.  
  43.  
  44.  
  45. <!-- JavaScript used to call the fileupload widget to upload files -->
  46. <script>
  47. // When the server is ready...
  48. $(function () {
  49. 'use strict';
  50.  
  51. // Define the url to send the image data to
  52. var url = 'files.php';
  53.  
  54. // Call the fileupload widget and set some parameters
  55. $('#fileupload').fileupload({
  56. url: url,
  57. dataType: 'json',
  58. done: function (e, data) {
  59. // Add each uploaded file name to the #files list
  60. $.each(data.result.files, function (index, file) {
  61. $('<li/>').text(file.name).appendTo('#files');
  62. });
  63. },
  64. progressall: function (e, data) {
  65. // Update the progress bar while files are being uploaded
  66. var progress = parseInt(data.loaded / data.total * 100, 10);
  67. $('#progress .bar').css(
  68. 'width',
  69. progress + '%'
  70. );
  71. }
  72. });
  73. });
  74.  
  75. </script>
  76. </div>
  77. </body>
  78. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement