Advertisement
MizunoBrasil

Compactador de Arquivos

Jan 16th, 2024
675
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="pt-br">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta name="author" content="Mizuno">
  7.     <title>Compactador de Arquivos</title>
  8.    
  9.     <script src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.5/jszip.min.js"></script>
  10.     <script src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"></script>
  11.     <style>
  12.         body {
  13.             font-family: Arial, sans-serif;
  14.             max-width: 600px;
  15.             margin: 20px auto;
  16.             text-align: center;
  17.         }
  18.  
  19.         input {
  20.             margin: 10px 0;
  21.         }
  22.  
  23.         button {
  24.             padding: 10px;
  25.             background-color: #4CAF50;
  26.             color: white;
  27.             border: none;
  28.             border-radius: 4px;
  29.             cursor: pointer;
  30.         }
  31.  
  32.         button:hover {
  33.             background-color: #45a049;
  34.         }
  35.     </style>
  36. </head>
  37. <body>
  38.     <h1>Compactador de Arquivos</h1>
  39.     <input type="file" id="fileInput" multiple>
  40.     <button onclick="compactar()">Compactar</button>
  41.  
  42.     <script>
  43.        
  44.         function compactar() {
  45.             var inputElement = document.getElementById('fileInput');
  46.             var files = inputElement.files;
  47.  
  48.             if (files.length > 0) {
  49.                 var zip = new JSZip();
  50.  
  51.                 for (var i = 0; i < files.length; i++) {
  52.                     var file = files[i];
  53.                     zip.file(file.name, file);
  54.                 }
  55.  
  56.                 var currentDate = new Date();
  57.                 var formattedDate = currentDate.toISOString().replace(/:/g, "-").split(".")[0];
  58.                 var zipFileName = "arquivo_" + formattedDate + ".zip";
  59.  
  60.                 zip.generateAsync({ type: "blob" })
  61.                     .then(function (content) {
  62.                         saveAs(content, zipFileName);
  63.                     });
  64.             } else {
  65.                 alert("Por favor, escolha pelo menos um arquivo.");
  66.             }
  67.         }
  68.     </script>
  69. </body>
  70. </html>
  71.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement