Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/04/2009, 16:27
Avatar de hoberwilly
hoberwilly
 
Fecha de Ingreso: julio-2008
Ubicación: Lima - Perú
Mensajes: 769
Antigüedad: 15 años, 10 meses
Puntos: 2
De acuerdo Grabar mas de un archivo en bd (forma binario)

Hola a todos,
Primero agradecer a GatorV y Pateketrueke por sus colaboraciones para llegar a finalizar la siguiente implementacion: "Grabar mas de un archivo en bd (en binario)". Y no olvidar en reconocer tambien el tutorial de Cluster que sirvio como base para las modificaciones del caso.

Asi que sin mas rodeo dejo este post para las personas como yo, que estamos iniciando en este mundo del php les puedan ser de utilidad. Y para aquellas compañeros que lo puedan mejorar (que acepte archivo de imagenes jpeg, png, gif; validar, etc) que nos seria de mucha ayuda.

Formulario:
Código php:
Ver original
  1. <!-- <html>
  2. <head>
  3. <title>FORMULARIO</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. </head>
  6. <body>
  7. <form name="form" method="post" enctype="multipart/form-data" action="insertarBlob.php">
  8. <table>
  9. <tr>
  10. <td align="right" width="19%">Foto 1:</td>
  11. <td width="61%"><input type="file" size="51" name="foto[]"></td>
  12. </tr>
  13. <tr>
  14. <td align="right" width="19%">Foto 2:</td>
  15. <td width="61%"><input type="file" size="51" name="foto[]"></td>
  16. </tr>
  17. <tr>
  18. <td align="right" width="19%">Foto 3:</td>
  19. <td width="61%"><input type="file" size="51" name="foto[]"></td>
  20. </tr>
  21. <td><input type="submit" name="enviar" value="Guardar"></td>
  22. <td><input type="reset" name="reset" value="Limpiar"></td>
  23. </table>
  24. </form>
  25. </body>
  26. </html>
  27.  -->
Archivo php:
Código php:
Ver original
  1. <!-- <?php
  2. $postback = (isset($_POST["enviar"])) ? true : false;
  3. if($postback)
  4. {
  5.   error_reporting(E_ALL);
  6.   include('conec.php');
  7.   conectarse();
  8.   $fotos=array();
  9.   foreach($_FILES['foto']['tmp_name'] as $foto){
  10.     $fotos[] = addslashes(file_get_contents($foto));
  11.   }
  12.   $tipos=array();
  13.   foreach($_FILES['foto']['type'] as $foto){
  14.     $tipos[] = $foto;
  15.   }
  16.   $fecha = date("Y-m-d H:i:s");
  17.   $sql = "INSERT INTO catalogo(id,foto,foto1,foto2,mime,mime1,mime2,fecha) VALUES('','$fotos[0]','$fotos[1]','$fotos[2]','$tipos[0]','$tipos[1]','$tipos[2]','$fecha')";
  18.   //echo $sql;
  19.   mysql_query($sql) or die( "Error: " . mysql_error());
  20.   echo "<h2>Foto guardada correctamente en la base de datos</h2>";
  21. }
  22. exit();
  23. ?> -->

Bye,