Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. <?php
  2.  
  3. <form action="usuario.php" method="POST" enctype="multipart/form-data">
  4. <label for="imagem">Imagem:</label>
  5. <input type="file" name="imagem"/>
  6. <br/>
  7. <input type="submit" value="Enviar"/>
  8. </form>
  9.  
  10.  
  11. ?>
  12.  
  13. <?php
  14.  
  15. $imagem = $_FILES["imagem"];
  16. $host = "localhost";
  17. $username = "root";
  18. $password = "";
  19. $db = "diligencia";
  20.  
  21. if($imagem != NULL) {
  22. $nomeFinal = time().'.jpg';
  23. if (move_uploaded_file($imagem['tmp_name'], $nomeFinal)) {
  24. $tamanhoImg = filesize($nomeFinal);
  25.  
  26. $mysqlImg = addslashes(fread(fopen($nomeFinal, "r"), $tamanhoImg));
  27.  
  28. mysql_connect($host,$username,$password) or die("Impossível Conectar");
  29.  
  30. @mysql_select_db($db) or die("Impossível Conectar");
  31.  
  32. mysql_query("INSERT INTO arquivos (arquivo) VALUES ('$mysqlImg')") or die("O sistema não foi capaz de executar a query");
  33.  
  34. unlink($nomeFinal);
  35.  
  36. header("location:exibir.php");
  37. }
  38. }
  39. else {
  40. echo"Você não realizou o upload de forma satisfatória.";
  41. }
  42.  
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement