Advertisement
SpeakeazyYT

Untitled

Jul 20th, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.84 KB | None | 0 0
  1. <script
  2.  src="https://code.jquery.com/jquery-3.4.1.min.js"
  3.  integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
  4.  crossorigin="anonymous"></script>
  5.  
  6. <style>
  7. .main_input_file {
  8.     display: none;
  9. }
  10.  
  11. .upload_form div {
  12.     height: 32px;
  13.     background: #3498db;
  14.     border-radius: 4px;
  15.     color: #fff;
  16.     text-align: center;
  17.     line-height: 32px;
  18.     font-family: arial;
  19.     font-size:14px;
  20.     display: inline-block;
  21.     vertical-align: top;
  22.     padding: 0 15;
  23. }
  24.  
  25. .upload_form div:hover {
  26.     background: #2980b9;
  27.     cursor: pointer;
  28. }
  29.  
  30. #f_name {
  31.     background: transparent;
  32.     border: 0;
  33.     display: inline-block;
  34.     vertical-align: top;
  35.     height: 30px;
  36.     padding: 0 8px;
  37.     width: 150px;
  38. }
  39. </style>
  40.  
  41. <form action="test.php" enctype="multipart/form-data" method="POST">
  42.  
  43. <div class="upload_form" id="file-upload">
  44.  
  45.     <label>
  46.  
  47.         <input type="file" class="main_input_file" name="files[]" multiple="multiple"/>
  48.         <div>Прикрепить файл</div>
  49.         <input class="f_name" type="text" id="f_name" value="Файлы не выбраны" disabled />
  50.  
  51.     </label>
  52.  
  53. </div>
  54.  
  55. <ul id="list-files"></ul>
  56.  
  57. <input name='button' type="submit" value="Загрузить">
  58.  
  59. </form>
  60.  
  61. <script>
  62.  
  63.     $(document).ready(function() {
  64.  
  65.         $(".main_input_file").change(function() {
  66.  
  67.             var f_name = [];
  68.                
  69.             //$("#list-files").empty();
  70.  
  71.             for (var i = 0; i < $(this).get(0).files.length; ++i) {
  72.                 file_type = $(this).get(0).files[i].type;
  73.                 if (file_type == 'image/png') {
  74.                     file_name = $(this).get(0).files[i].name;
  75.                     f_name.push(" " + file_name);
  76.                     $("#list-files").append("<li>"+ file_name +"</li>");
  77.                 } else {
  78.                     $("#list-files").append("<li>Файл имеет недопустимое расширение.</li>");
  79.                 }
  80.             }
  81.  
  82.             $("#f_name").val("Число файлов: "+$("#list-files li").length);
  83.         });
  84.  
  85.     });
  86.  
  87. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement