Guest User

Untitled

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