D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
html
/
crsys_ant
/
Filename :
testeupload.php
back
Copy
<!DOCTYPE html> <html lang="pt-BR"> <head> <meta charset="UTF-8"> <title>Upload de Imagem</title> <style> /* ===== CONTAINER PRINCIPAL (400x400 AO REDOR DO FORM E IMAGEM) ===== */ .box-350 { width: 350px; height: 350px; border: 2px solid #777; padding: 10px; display: flex; flex-direction: column; gap: 10px; justify-content: flex-start; align-items: center; box-sizing: border-box; background: #f8f8f8; } /* ===== FORMULÁRIO ===== */ .custom-file-label { display: inline-block; padding: 6px 12px; border: 1px solid #777; background-color: #eee; cursor: pointer; user-select: none; } /* Esconde o input real */ input[type="file"] { display: none; } /* ===== ÁREA DE PRÉ-VISUALIZAÇÃO 300x300 ===== */ .container-img { width: 300px; height: 300px; border: 1px solid #ccc; overflow: hidden; display: flex; justify-content: center; align-items: center; background: #fff; } .container-img img { width: 100%; height: 100%; object-fit: cover; /* Ajusta ao container sem distorcer */ } </style> </head> <body> <div class="box-350"> <!-- FORMULÁRIO --> <form action="upload.php" method="POST" enctype="multipart/form-data"> <label for="input-img" class="custom-file-label">Selecione</label> <input type="file" id="input-img" name="imagem" accept="image/*" required> <button type="submit">Enviar</button> </form> <!-- PRÉ-VISUALIZAÇÃO DA IMAGEM --> <div class="container-img"> <img id="preview-img" src="" alt="Pré-visualização"> </div> </div> <script> // ===== PREVIEW AUTOMÁTICO DA IMAGEM ===== document.getElementById("input-img").addEventListener("change", function () { const file = this.files[0]; const preview = document.getElementById("preview-img"); const label = document.querySelector(".custom-file-label"); if (file) { const reader = new FileReader(); reader.onload = function (e) { preview.src = e.target.result; }; reader.readAsDataURL(file); // Alterar texto do label para o nome do arquivo label.textContent = file.name; } else { preview.src = ""; // limpa preview se nenhum arquivo label.textContent = "Selecione"; } }); </script> </body> </html>