Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //CONTIDO DO INDEX.PHP
  2.  
  3.  
  4.  
  5.  
  6. <form action="procesar.php" enctype="multipart/form-data" method="post">
  7. <label for="image">Image:</label>
  8. <input id="image" name="image" size="30" type="file" />
  9.  
  10. <input name="submit" type="submit" value="Gardar" />
  11. </form>
  12.  
  13.  
  14.  
  15. //CONTIDO DO procesar.php
  16.  
  17.  
  18.  
  19. <?php
  20.  
  21. // Datos de conexión a configurar
  22. $user = "esquio";
  23. $pass = "esquigaliza";
  24. $bbdd = "esquio";
  25.  
  26. // Ruta donde se guardarán las imágenes
  27. $directorio = $_SERVER['DOCUMENT_ROOT'].'/uploads/';
  28.  
  29. // Conecto a la BBDD
  30. $dbh = mysql_connect("sql.esquio.dreamhosters.com", $user, $pass);
  31. $db = mysql_select_db($bbdd);
  32.  
  33. // Recibo los datos de la imagen
  34. $nombre = $_FILES['imagen']['name'];
  35. $tipo = $_FILES['imagen']['type'];
  36. $tamano = $_FILES['imagen']['size'];
  37.  
  38. // Muevo la imagen desde su ubicación
  39. // temporal al directorio definitivo
  40. move_uploaded_file($_FILES['imagen']['tmp_name'],$directorio.$nombre);
  41.  
  42.  
  43. // Guardamos en la BBDD
  44. $sql = "INSERT into images (nombre_arquivo) values ('$nombre')";
  45. $resultado = mysql_query($sql);
  46.  
  47. // Por si queremos la ID asignada a la imagen
  48. $id = mysql_insert_id();
  49. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement