Ver Mensaje Individual
  #5 (permalink)  
Antiguo 06/03/2009, 16:04
Avatar de hoberwilly
hoberwilly
 
Fecha de Ingreso: julio-2008
Ubicación: Lima - Perú
Mensajes: 769
Antigüedad: 15 años, 10 meses
Puntos: 2
Respuesta: Subir imagenes a bd (mas de 1)

Hola a todos, este es el avanze segun lo sugerido por Nefertiter
formularioBlob.php
Código php:
Ver original
  1. <!-- <html>
  2. <head>
  3. <title>Imagen a Blob</title>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. </head>
  6. <body>
  7. <form name="frmimage" method="post" enctype="multipart/form-data" action="include/insertarBlob.php">
  8. <table>
  9. <tr>    <td align="right" width="19%">Foto 1:</td>
  10.     <td width="61%"><input type="file" size="51" name="foto[]"></td>
  11. </tr>
  12. <tr>    <td align="right" width="19%">Foto 2:</td>
  13.     <td width="61%"><input type="file" size="51" name="foto[]"></td>
  14. </tr>
  15. <tr>    <td align="right" width="19%">Foto 3:</td>
  16.     <td width="61%"><input type="file" size="51" name="foto[]"></td>
  17. </tr>
  18. </table>
  19. <center>
  20. <table border=0 cellpadding=15>
  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.  -->
insertarBlob.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.   $mimetypes = array("image/jpeg", "image/pjpeg", "image/gif", "image/png");
  9.   for($i=0;$i<=count($_FILES['foto']);$i++)
  10.   {
  11.     //obtener del array FILES (superglobal) los datos del binario...nombre, tipo, tamaño
  12.     $size = $_FILES["foto"]["size"][$i];           //linea 12
  13.     $name = $_FILES["foto"]["name"][$i];      //linea 13
  14.     $type = $_FILES["foto"]["type"][$i];         //linea 14
  15.     if(!in_array($type,$mimetypes))
  16.     die("El archivo que subiste no es una imagen válida");
  17.     //archivo temporal (ruta y nombre)
  18.     $tmp_name = $_FILES["foto"]["tmp_name"][$i];
  19.     //leer el archivo temporal
  20.     $fp = fopen($tmp_name,"rb");
  21.     //filesize: obtiene el tamaño del archivo
  22.     //fread: lectura de archivos segura con material binario
  23.     $tfoto = fread($fp, filesize($tmp_name));
  24.     //escapa una cadena insertando barras "\"
  25.     $tfoto[$i] = addslashes($tfoto);
  26.     fclose($fp);
  27.     @unlink($tmp_name);
  28.   }
  29.     $sql1 = "INSERT INTO catalogo(id,foto,foto1,foto2) VALUES('','".$tfoto[0]."','".$tfoto[1]."','".$tfoto[2]."')";          //ojo el campo id es autoincrement
  30.     mysql_query($sql1) or die( "Error: " . mysql_error());
  31.  
  32.   echo "<h2>Foto guardada correctamente en la base de datos</h2>";
  33. }
  34. exit();
  35. ?> -->
pero me sale estos msjes de error:
Notice: Undefined offset: 3 in /home/nando/public_html/include/insertarBlob.php on line 12
Notice: Undefined offset: 3 in /home/nando/public_html/include/insertarBlob.php on line 13
Notice: Undefined offset: 3 in /home/nando/public_html/include/insertarBlob.php on line 14
El archivo que subiste no es una imagen válida