Foros del Web » Programando para Internet » PHP »

Adjuntar multiples fotos

Estas en el tema de Adjuntar multiples fotos en el foro de PHP en Foros del Web. Hola a todos: Tengo los siguientes formularios de inserción de foto que funciona correctamente con la inserción de 1 foto. Me gustaría poder adjuntar un ...
  #1 (permalink)  
Antiguo 15/12/2010, 05:22
 
Fecha de Ingreso: julio-2010
Ubicación: Cerca Sitges (Barcelona)
Mensajes: 98
Antigüedad: 13 años, 9 meses
Puntos: 4
Adjuntar multiples fotos

Hola a todos:
Tengo los siguientes formularios de inserción de foto que funciona correctamente con la inserción de 1 foto.
Me gustaría poder adjuntar un total de 5 fotos, y en el caso de que el usuario no adjunte todas las fotos, poder adjuntar una imagen de fondo (que se encontrará en el servidor con la ruta (/datos internos/fotos/ico_sin_foto.gif) para poder suplir la ausencia de la/s foto/s.

Muchas gracias.

Código PHP:
Ver original
  1. <div id="mainContent">
  2.     <h1><form method = "post" name = "procedim" action = "22.php" enctype="multipart/form-data">
  3.       <p><br>
  4.            nombre: <input type = "text" name = "nombre"><br>
  5.            apellido: <input type = "text" name = "apellido"><br>
  6.            ciudad: <input type = "text" name = "ciudad"><br>
  7.            provincia: <input type = "text" name = "provincia"><br>
  8.            web: <input type = "text" name = "web"><br>
  9.            tituloanuncio: <input type = "text" name = "tituloanuncio"><br>
  10.            precio: <input type = "text" name = "precio">
  11.       </p>
  12.       <p>imagen:
  13.         <input type = "file" name= "foto1" />
  14.         <br>
  15.         <input type = "submit" name = "boton" value = "Registrar Laptop"><br>
  16.       </p>
  17.     </form>&nbsp;</h1>

Código PHP:
Ver original
  1. <?php require_once('../../Connections/contactos.php'); ?>
  2. <?php
  3. if (!function_exists("GetSQLValueString")) {
  4. function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
  5. {
  6.   if (PHP_VERSION < 6) {
  7.     $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  8.   }
  9.  
  10.   $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
  11.  
  12.   switch ($theType) {
  13.     case "text":
  14.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  15.       break;    
  16.     case "long":
  17.     case "int":
  18.       $theValue = ($theValue != "") ? intval($theValue) : "NULL";
  19.       break;
  20.     case "double":
  21.       $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
  22.       break;
  23.     case "date":
  24.       $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
  25.       break;
  26.     case "defined":
  27.       $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
  28.       break;
  29.   }
  30.   return $theValue;
  31. }
  32. }
  33.  
  34. mysql_select_db($database_contactos, $contactos);
  35. $query_Recordset1 = "SELECT * FROM contactos";
  36. $Recordset1 = mysql_query($query_Recordset1, $contactos) or die(mysql_error());
  37. $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  38. $totalRows_Recordset1 = mysql_num_rows($Recordset1);
  39.  
  40. //_________
  41.  
  42.     <h1><?
  43. $db=mysql_connect("localhost","????","????",$db);
  44.     mysql_select_db("????",$db);
  45.  
  46. $nombre=$_POST[nombre];
  47.     $apellido=$_POST[apellido];
  48.     $ciudad=$_POST[ciudad];
  49.     $provincia=$_POST[provincia];
  50.     $web=$_POST[web];
  51.     $tituloanuncio=$_POST[tituloanuncio];
  52.     $precio=$_POST[precio];
  53.     $foto1 = $_FILES['foto1']['name'];
  54.    
  55.    // aqui tenias un error, tenias un ; al final de los values ...'$precio');
  56.    // "directorio" es el directorio donde vas a subir la imagen.
  57.     mysql_query("insert into contactos(foto1 , nombre , apellido , ciudad , provincia , web , tituloanuncio , precio)
  58. values('/imagenes/$foto1','$nombre','$apellido','$ciudad','$provincia','$web','$tituloanuncio','$precio')",$db) or die("La clave introducida, ya existe. Elige otra");
  59.  
  60. //ahora subamos la imagen, "directorio" es el directorio donde la vas a subir.
  61. $copy = copy($_FILES['foto1']['tmp_name'], "../../imagenes/" . $_FILES['foto1']['name']);
  62. ?>&nbsp;</h1>
  63.     <!-- end #mainContent --></div>
  64.     <!-- Este elemento de eliminación siempre debe ir inmediatamente después del div #mainContent para forzar al div #container a que contenga todos los elementos flotantes hijos --><br class="clearfloat" />
  65.   <div id="footer">
  66.     <p>Pie</p>
  67.   <!-- end #footer --></div>
  68. <!-- end #container --></div>
  69. </body>
  70. </html>
  71. <?php
  72. mysql_free_result($Recordset1);
  73. ?>
  74.  
  75. ?>

Gracias a todos.
  #2 (permalink)  
Antiguo 15/12/2010, 05:29
 
Fecha de Ingreso: marzo-2008
Mensajes: 1.020
Antigüedad: 16 años, 1 mes
Puntos: 21
Respuesta: Adjuntar multiples fotos

Ver en este foro

o

Con jQuery multi uploader?

Saludos.

Etiquetas: fotos, multiples
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 21:39.