Advertisement
Guest User

Untitled

a guest
May 26th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3.  
  4. <head>
  5. <meta charset="utf-8"/>
  6. <title>File Uploader</title>
  7.  
  8. <!-- Google web fonts -->
  9. <link href="http://fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700" rel='stylesheet' />
  10.  
  11. <!-- The main CSS file -->
  12. <link href="assets/css/style.css" rel="stylesheet" />
  13. </head>
  14.  
  15. <body>
  16.  
  17. <form id="upload" method="post" action="upload.php" enctype="multipart/form-data">
  18. <div id="drop">
  19. Drop Here
  20.  
  21. <a>Browse</a>
  22. <input type="file" name="upl[]" multiple />
  23. </div>
  24.  
  25. <ul>
  26. <!-- The file uploads will be shown here -->
  27. </ul>
  28.  
  29. </form>
  30.  
  31. <!-- JavaScript Includes -->
  32. <script src="assets/js/jquery-1.11.3.min.js"></script>
  33. <script src="assets/js/jquery.knob.js"></script>
  34.  
  35. <!-- jQuery File Upload Dependencies -->
  36. <script src="assets/js/jquery.ui.widget.js"></script>
  37. <script src="assets/js/jquery.iframe-transport.js"></script>
  38. <script src="assets/js/jquery.fileupload.js"></script>
  39.  
  40. <!-- Our main JS file -->
  41. <script src="assets/js/script.js"></script>
  42.  
  43.  
  44. </body>
  45. </html>
  46.  
  47. $(function(){
  48.  
  49. var ul = $('#upload ul');
  50. var myfiles = [];
  51. $('#drop a').click(function(){
  52. // Simulate a click on the file input button
  53. // to show the file browser dialog
  54. $(this).parent().find('input').click();
  55. });
  56.  
  57. // Initialize the jQuery File Upload plugin
  58. $('#upload').fileupload({
  59.  
  60. // This element will accept file drag/drop uploading
  61. dropZone: $('#drop'),
  62.  
  63. // This function is called when a file is added to the queue;
  64. // either via the browse button, or via drag/drop:
  65. add: function (e, data) {
  66.  
  67. var tpl = $('<li class="working"><input type="text" value="0" data-width="48" data-height="48"'+
  68. ' data-fgColor="#0788a5" data-readOnly="1" data-bgColor="#3e4043" /><p></p><span></span></li>');
  69.  
  70. // Append the file name and file size
  71. tpl.find('p').text(data.files[0].name)
  72. .append('<i>' + formatFileSize(data.files[0].size) + '</i>');
  73.  
  74. // Add the HTML to the UL element
  75. data.context = tpl.appendTo(ul);
  76.  
  77. // Initialize the knob plugin
  78. tpl.find('input').knob();
  79.  
  80. // Listen for clicks on the cancel icon
  81. tpl.find('span').click(function(){
  82.  
  83. if(tpl.hasClass('working')){
  84. jqXHR.abort();
  85. }
  86.  
  87. tpl.fadeOut(function(){
  88. tpl.remove();
  89. });
  90.  
  91. });
  92.  
  93. // Automatically upload the file once it is added to the queue
  94. var jqXHR = data.submit();
  95. },
  96.  
  97. progress: function(e, data){
  98.  
  99. // Calculate the completion percentage of the upload
  100. var progress = parseInt(data.loaded / data.total * 100, 10);
  101.  
  102. // Update the hidden input field and trigger a change
  103. // so that the jQuery knob plugin knows to update the dial
  104. data.context.find('input').val(progress).change();
  105.  
  106. if(progress == 100){
  107. data.context.removeClass('working');
  108. }
  109. },
  110.  
  111. fail:function(e, data){
  112. // Something has gone wrong!
  113. data.context.addClass('error');
  114. }
  115.  
  116. });
  117.  
  118.  
  119. // Prevent the default action when a file is dropped on the window
  120. $(document).on('drop dragover', function (e) {
  121. e.preventDefault();
  122. });
  123.  
  124. // Helper function that formats the file sizes
  125. function formatFileSize(bytes) {
  126. if (typeof bytes !== 'number') {
  127. return '';
  128. }
  129.  
  130. if (bytes >= 1000000000) {
  131. return (bytes / 1000000000).toFixed(2) + ' GB';
  132. }
  133.  
  134. if (bytes >= 1000000) {
  135. return (bytes / 1000000).toFixed(2) + ' MB';
  136. }
  137.  
  138. return (bytes / 1000).toFixed(2) + ' KB';
  139. }
  140.  
  141. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement