Advertisement
SpeakeazyYT

Untitled

Jul 21st, 2019
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.02 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 id="myForm" action="test.php" method="post" enctype="multipart/form-data">
  42.     <div class="upload_form">
  43.         <div class="addFiles">Прикрепить файл</div>
  44.         <input class="f_name" type="text" id="f_name" value="Файлы не выбраны" disabled />
  45.     </div>
  46.  
  47.     <ul id="list-files"></ul>
  48.  
  49.     <input name='button' type="submit" value="Загрузить">
  50. </form>
  51.  
  52. <script>
  53. $('.addFiles').on('click', function() {
  54.     $('.upload_form').prepend('<input type="file" class="main_input_file" name="arrFiles[]" multiple="multiple"/>')
  55.   $('.main_input_file:last', myForm).click()
  56. })
  57.  
  58. $('#myForm').on('click', '.imgGroup .del', function(){
  59.     $(this).closest('.imgGroup').remove()
  60. })
  61.  
  62. $(document).ready(function() {
  63.  
  64.     $(".main_input_file").change(function() {
  65.  
  66.         var f_name = [];
  67.            
  68.         //$("#list-files").empty();
  69.  
  70.         for (var i = 0; i < $(this).get(0).files.length; ++i) {
  71.             file_type = $(this).get(0).files[i].type;
  72.             if (file_type == 'image/png') {
  73.                 file_name = $(this).get(0).files[i].name;
  74.                 f_name.push(" " + file_name);
  75.                 $("#list-files").append("<li>"+ file_name +"</li>");
  76.             } else {
  77.                 $("#list-files").append("<li>Файл имеет недопустимое расширение.</li>");
  78.             }
  79.         }
  80.  
  81.         $("#f_name").val("Число файлов: "+$("#list-files li").length);
  82.     });
  83.  
  84. });
  85.  
  86. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement