Advertisement
Geicy

Untitled

Jul 7th, 2021
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.83 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4. <?php
  5. if(isset($_POST['enviar-formulario'])):
  6.     $formatosPermitidos = array("png", "jpeg", "jpg", "gif");
  7.     $extensao = pathinfo($_FILES['arquivo']['name'], PATHINFO_EXTENSION);
  8.  
  9.     if(in_array($extensao, $formatosPermitidos)):
  10.         $pasta = "arquivos/";
  11.         $temporaio = $_FILES['arquivo']['tmp_name'];
  12.         $novoNome = uniqid().".$extensao";
  13.  
  14.         if(move_uploaded_file($temporaio, $pasta.$novoNome)):
  15.             $mensagem = "Upload concluido com sucesso!";
  16.         else:
  17.             $mensagem = "Erro, não foi possivel fazer upload";
  18.         endif;
  19.     else:
  20.         $messagem = "Formato inválido";
  21.     endif;
  22.  
  23. echo $mensagem;
  24.  
  25. endif;
  26. ?>
  27.  
  28. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST"
  29.     enctype="multipart/form-data">
  30.     <input type="file" name="arquivo"><br>
  31.     <input type="submit" name="enviar-formulario">
  32. </form>
  33.  
  34. </body>
  35. </html>
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement