Foros del Web » Programando para Internet » PHP »

como subir varias imagenes en php

Estas en el tema de como subir varias imagenes en php en el foro de PHP en Foros del Web. Buenas tardes tengo un problema para editar el siguiente codigo, resulta que edite un sistema de imagenes para noticias, y funcionaba bien, ahora, el problema ...
  #1 (permalink)  
Antiguo 26/01/2012, 13:38
 
Fecha de Ingreso: enero-2012
Ubicación: cabudare
Mensajes: 5
Antigüedad: 12 años, 2 meses
Puntos: 0
Mensaje como subir varias imagenes en php

Buenas tardes tengo un problema para editar el siguiente codigo, resulta que edite un sistema de imagenes para noticias, y funcionaba bien, ahora, el problema es que el cliente ahora quiere que en vez de una foto tena varias. si alguien me puede ayudar.

este es el codigo del formulario

<?php
$chequeoone= $_GET['Id'];
//echo $chequeoone;
If($_GET['Id'] == "") {


//echo " entra al get ID noticias";
//echo $chequeo;

}
else {

include("functions.php");
// echo "cuando entra al else del get";
$link = conectar();
conectardb();

//Ejecutamos la sentencia SQL
$query = mysql_query("SELECT * from noticias where month(fecha) = ". $_GET['Id'] ." Order By fecha desc",$link);

$total = mysql_num_rows($query);

if($total == 0) {
echo '<font style="color:red">No se encontraron noticias registradas para el mes seleccionado.</font>';
}
else {

echo '<table width="650" border="0" cellpadding="0" cellspacing="0"><tr>';
echo '<th align="left" width="180" scope="col" >Titulo</th>';
echo '<th align="left" width="180" scope="col" >Descripcin</th>';
echo '<th align="left" width="180" scope="col" >Detalle</th>';
echo '<th align="right" width="52" scope="col" >Fecha</th>';
echo '<th width="50" scope="col">&nbsp;</th>';
echo '</tr></table>';

$apuntador = 0;
while ($fila=mysql_fetch_array($query))
{
$apuntador ++;
if(pow(-1,$apuntador) == 1) {
$ColorFila = "#05a4cc"; //color de CE9DFF
}
else
{
$ColorFila = "#0abfe4"; // color de fondo del reporte ECD9FF
}
echo '<table height="25" bgcolor="' . $ColorFila . '" width="650" border="0" cellpadding="0" cellspacing="0"><tr>';
echo '<th align="left" width="180" scope="col" >&nbsp;&nbsp;' . cut_cadena($fila['titulo'], 18) . '</th>';
echo '<th align="left" width="180" scope="col" >' . cut_cadena($fila['descripcion'], 25) . '</th>';
echo '<th align="left" width="180" scope="col" >' . cut_cadena($fila['detalle'], 25) . '</th>';
echo '<th align="right" nowrap="nowrap" width="52" scope="col" >' . $fila['fecha'] . '</th>';
echo '<th align="center" width="25" scope="col"><a href="enoticia.php?Id=' . $fila['id_noticia'] . '&Idmes=' . $_GET['Id'] . '"><img src="imagenes/ipanel/Editar16x16.png" width="16" height="16" border="0" /></a></th>';
echo '<th align="center" width="25" scope="col"><a href="eliminarnoticia.php?Id=' . $fila['id_noticia'] . '&Idmes=' . $_GET['Id'] . '&file=' . $fila['foto'] . '"><img src="imagenes/ipanel/Eliminar16x16.png" width="16" height="16" border="0" /></a></th>';
echo '</tr></table>';
}
}

mysql_free_result($query);
mysql_close($link);

echo '</p>';

echo '<table width="650" border="0" cellpadding="0" cellspacing="0">
<tr>
<th scope="col">&nbsp;</th>
</tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0" height="20">
<tr>
<th width="36" scope="col" align="center">&nbsp;<img src="imagenes/ipanel/Nuevo.png" width="25" height="25" /></th>
<th width="612" scope="col" align="left">&nbsp;&nbsp;Agregar Noticia
</tr>
<tr height="15">
<th scope="col" align="center">&nbsp;</th>
<th scope="col" align="left" >&nbsp;</th>
</tr>
</table>
<form action="guardarnoticia.php" enctype="multipart/form-data" method="post">
<table width="650" border="0">
<tr>
<th width="134" scope="col" valign="top" align="left"> Titulo</th>
<th width="506" scope="col" valign="top" align="left"><input name="titulo" type="text" id="Titulo" size="80%"/>
</label></th>
</tr>
<tr>
<th scope="col" valign="top" align="left">Descripci&oacute;n</th>
<th scope="col" valign="top" align="left"><label>
<textarea name="descripcion" cols="60%" rows="8" id="Desripcion"></textarea>
</label></th>
</tr>
<tr>
<th scope="col" valign="top" align="left">Detalle</th>
<th scope="col" valign="top" align="left"><textarea name="detalle" cols="60%" rows="8" id="detalle"></textarea></th>
</tr>
<tr>
<th scope="col" valign="top" align="left">Dia, Mes, A&ntilde;o </th>
<th scope="col" valign="top" align="left"><select name="dia">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
</label>
<select name="mes">
<option value="1">Enero</option>
<option value="2">Febrero</option>
<option value="3">Marzo</option>
<option value="4">Abril</option>
<option value="5">Mayo</option>
<option value="6">Junio</option>
<option value="7">Julio</option>
<option value="8">Agosto</option>
<option value="9">Septiembre</option>
<option value="10">Octubre</option>
<option value="11">Noviembre</option>
<option value="12">Diciembre</option>
</select>
<select name="anho">
<option value="2007">2007</option>
<option value="2008">2008</option>
<option value="2009" selected="selected">2009</option>
<option value="2010">2010</option>
<option value="2011">2011</option>
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
<option value="2019">2019</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
</select></th>
</tr>
<tr>
<th scope="col" valign="top" align="left">Fotograf&iacute;a</th>

<th scope="col" valign="top" align="left">
<input name="foto" type="file" size="60%"/>
<input value="';
echo $_GET['Id'];
echo '" type="hidden" name="idmes"/></th>
</tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0">
<tr>
<th scope="col">&nbsp;</th>
</tr>
</table>
<table width="650" border="0" cellpadding="0" cellspacing="0">
<tr>
<th scope="col"><input type="submit" name="submit" value="Guardar" class="Boton" /></th>
</tr>
<tr>
<th scope="col">&nbsp;</th>
</tr>
</table>
</form>';
}
?>

y este es el php

<?php
include("../functions.php");

$link=conectar();
conectardb();

$titulo=$_POST['titulo'];
$descripcion=$_POST['descripcion'];
$detalle=$_POST['detalle'];
//$foto=$_FILES['foto']['name']; //nombre de la foto
$foto = $HTTP_POST_FILES['foto'];
$count = count($foto);
for($i=0;$i<$count;$i++){
echo $foto[$i]['tmp_name'];
}

//lo que se guarda en bd

//echo $foto;
$fecha = $_POST['anho'].'/'.$_POST['mes'].'/'.$_POST['dia'];
//echo $fecha;
$valor=$_FILES['foto']['tmp_name'];
//echo $valor;
$query0=mysql_query("SELECT * FROM noticias where foto = '$foto'" ,$link);

$total0=mysql_num_rows($query0);

if (($total0=="0") && ($titulo!="") && ($descripcion!="") && ($detalle!="") && ($foto!="")) {
//luego con esta instruccion muevo la imagen a una carpeta dentro de mi servidor
mysql_query("insert into noticias (titulo,descripcion,detalle,foto,fecha) values ('$titulo','$descripcion','$detalle','$foto','$fec ha')",$link);

copy($_FILES['foto']['tmp_name'],'fotos/noticias/' . $_FILES['foto']['name']);

//$fotoname=$_FILES['foto']['name'];
//echo $fotoname;
$chequeo=$_POST['idmes']; //numero del mes
//echo $chequeo;
header("Location: noticias.php?Id=" . $_POST['idmes']);
}
else{
header("Location: noticias.php?Error=1");
}?>

si alguien me ayuda le estare muy agradecido
  #2 (permalink)  
Antiguo 26/01/2012, 14:01
Avatar de andresdzphp
Colaborador
 
Fecha de Ingreso: julio-2011
Ubicación: $this->Colombia;
Mensajes: 2.749
Antigüedad: 12 años, 9 meses
Puntos: 793
Respuesta: como subir varias imagenes en php

Aquí explican como subir varios archivos

http://www.php.net/manual/es/feature...d.multiple.php

Vi por encima el código, pero en vez de $HTTP_POST_FILES, debes usar $_FILES.

Otro link que te puede servir:

http://www.w3schools.com/php/php_file_upload.asp

Un aporte en el FAQ del foro

¿Cómo hago para subir mas de 1 archivo, o talvez las cantidad que yo desee sin limitaciones?

Saludos.
__________________
Si sabemos como leer e interpretar el manual será mucho más fácil aprender PHP. En lugar de confiar en ejemplos o copiar y pegar - PHP
  #3 (permalink)  
Antiguo 26/01/2012, 16:44
 
Fecha de Ingreso: enero-2012
Ubicación: cabudare
Mensajes: 5
Antigüedad: 12 años, 2 meses
Puntos: 0
Respuesta: como subir varias imagenes en php

gracias andresdzphp, voy a revisar los link (Y)
  #4 (permalink)  
Antiguo 26/01/2012, 17:43
 
Fecha de Ingreso: enero-2012
Ubicación: cabudare
Mensajes: 5
Antigüedad: 12 años, 2 meses
Puntos: 0
Respuesta: como subir varias imagenes en php

andresdzphp de verdad me gusto mucho este codigo:

<form action="" method="post" enctype="multipart/form-data" name="form1">
Cantidad: <select name="cantidad">
<script type="text/javascript">
for(x=1;x<=10;x++){
document.write("<option value="+ x +">"+ x+"</option>");
}
</script>
</select>
<input type="submit" name="Submit" value="Submit"><br>


<?php
$uploaddir=$_SERVER['DOCUMENT_ROOT']."/upload/imagenes/";

if(isset($_POST['Submit'])){
echo "Elegir Im&aacute;genes para Subir<br>";
for($i=1;$i<=$_POST['cantidad'];++$i){
echo "<input type=\"file\" name=\"archivo[]\"><br>";
}
echo "<input type=\"submit\" name=\"Submit2\" value=\"Submit2\">";
echo "<input type=\"hidden\" name=\"cant1\" value=\"$i\">";
}

if(isset($_POST['Submit2'])){
$cantidad2 =count($_FILES["archivo"]);
for ($j=0;$j<=$cantidad2;$j++){
$archivo = $_FILES["archivo"]["tmp_name"][$j];
$tamanio = $_FILES["archivo"]["size"][$j];
$tipo = $_FILES["archivo"]["type"][$j];
$nombre = $_FILES["archivo"]["name"][$j];

$x=$j;
do{
$x++;
if( $archivo != "" ){
$fp = fopen($archivo, "rb");
$contenido = fread($fp, $tamanio);
$contenido = addslashes($contenido);
fclose($fp);
//AQUI INSERTE EN LA BASE DE DATOS

if(copy($archivo, $uploaddir.$nombre))
{
echo $nombre." Subido con Exito<br>";
}
}
}while($x<$j);
}
}
?>
</form>

pero como no soy muy experto no logre como insertarlo en el codigo que tengo arriba, si me dices como por fa!

Etiquetas: formulario, imagenes, mysql, sql
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 09:01.