Upload de imagens
Publicado por adrianosalles (última atualização em 28/09/2009)
[ Hits: 7.130 ]
Script para fazer o upload de imagens com validações.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <?php if(isset($_POST["enviar"])) { $arquivo = $_FILES["imagem"]["name"]; // verifica se o arquivo não tem caracteres especias $arquivo = str_replace("á","a",$arquivo); $arquivo = str_replace("â","a",$arquivo); $arquivo = str_replace("à","a",$arquivo); $arquivo = str_replace("ã","a",$arquivo); $arquivo = str_replace("é","e",$arquivo); $arquivo = str_replace("è","e",$arquivo); $arquivo = str_replace("ê","e",$arquivo); $arquivo = str_replace("ò","o",$arquivo); $arquivo = str_replace("ó","o",$arquivo); $arquivo = str_replace("ô","o",$arquivo); $arquivo = str_replace("õ","o",$arquivo); $arquivo = str_replace("í","i",$arquivo); $arquivo = str_replace("ì","i",$arquivo); $arquivo = str_replace(" ","_",$arquivo); //coloca o nome do arquivo todo em minúsculas $arquivo = strtolower($arquivo); //verifica se é um arquivo valido if(!eregi("^image\/(gif|jpg|jpeg|pjpg)",$_FILES["imagem"]["type"])) { print "<script>alert(\"nao e um arquivo valido\");</script>"; } else { //verifica se o nome do arquivo já existe if(file_exists($arquivo)) { $a=1; while(file_exists("[$a]$arquivo")) { $a++; } $arquivo = "[$a]$arquivo"; } //verifica se o arquivo foi copiado com sucesso para o diretório if(!move_uploaded_file($_FILES["imagem"]["tmp_name"],$arquivo)) { print "<script>alert(\"Falha ao carregar o arquivo\");</script>"; } print "<script>alert(\"Arquivo carregado com sucesso\");</script>"; } } ?> <form action="" method="post" enctype="multipart/form-data" name="form1"> <table width="30%" border="0" align="center"> <tr> <td>Enviar uma imagem:</td> <td>Sim <input name="enviar" type="radio" value="sim" onclick="document.form1.imagem.disabled=false;" /> Não <input name="enviar" type="radio" value="nao" checked="checked" /></td> </tr> <tr> <td>Imagem:</td> <td><input name="imagem" type="file" disabled="true" /></td> </tr> <tr> <td colspan="2"><div align="center"><input name="enviar" type="submit" value="Enviar" /></div></td> </tr> </table> </form> </body> </html>
Manipulação de Arquivos XML para OT Server
Visualizador de Imagens em PHP-GTK2
Nenhum comentário foi encontrado.
tux-gpt - Assistente de IA para o Terminal
Instalação e configuração do Chrony
Programa IRPF - Guia de Instalação e Resolução de alguns Problemas
O Que Fazer Após Instalar Ubuntu 25.04
O Que Fazer Após Instalar Fedora 42
Debian 12 -- Errata - Correções de segurança
Instalando o Pi-Hole versão v5.18.4 depois do lançamento da versão v6.0
Alguém poderia me ajudar a escolher peças pra montar um desktop? (22)
Pra quem contribui com artigos e dicas (2)
Copiar Layout do Teclado para aplicar em outra Distribuição (2)