Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Upload de Arquivo</title>
- <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;700&display=swap">
- <style>
- body {
- font-family: 'Poppins', sans-serif;
- background-color: #f0f0f0;
- display: flex;
- align-items: center;
- justify-content: center;
- height: 100vh;
- margin: 0;
- }
- .container {
- text-align: center;
- color: #333;
- }
- form {
- background-color: #ffffff;
- padding: 20px;
- border-radius: 8px;
- box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
- display: flex;
- flex-direction: column;
- align-items: center;
- margin-top: 20px;
- }
- input, button {
- margin-bottom: 10px;
- padding: 10px;
- width: 100%;
- box-sizing: border-box;
- }
- button {
- cursor: pointer;
- background-color: #4caf50;
- color: white;
- border: none;
- border-radius: 4px;
- transition: background-color 0.3s;
- }
- button:hover {
- background-color: #45a049;
- }
- </style>
- </head>
- <body>
- <form id="uploadForm">
- <label for="fileInput"><h2>Renomear Arquivo</h2></label>
- <p>o nome do arquivo será no formato <b>aaaa-mm-dd-hh-mm-ss</b></p>
- <input type="file" id="fileInput" accept="image/*" required>
- <button type="button" onclick="uploadFile()">Enviar</button>
- </form>
- <script>
- function uploadFile() {
- var fileInput = document.getElementById('fileInput');
- var file = fileInput.files[0];
- if (file) {
- var currentDate = new Date();
- var uniqueFileName = currentDate.getFullYear() + '-' +
- pad(currentDate.getMonth() + 1) + '-' +
- pad(currentDate.getDate()) + '-' +
- pad(currentDate.getHours()) + '-' +
- pad(currentDate.getMinutes()) + '-' +
- pad(currentDate.getSeconds());
- var fileExtension = file.name.split('.').pop();
- var newFileName = uniqueFileName + "." + fileExtension;
- var blob = new Blob([file], { type: file.type });
- var link = document.createElement('a');
- link.href = window.URL.createObjectURL(blob);
- link.download = newFileName;
- document.body.appendChild(link);
- link.click();
- document.body.removeChild(link);
- } else {
- alert("Por favor, selecione um arquivo.");
- }
- }
- function pad(number) {
- return (number < 10 ? '0' : '') + number;
- }
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement