Foros del Web » Programando para Internet » PHP »

problemas con tutorial para subir varias imagenes a la vez

Estas en el tema de problemas con tutorial para subir varias imagenes a la vez en el foro de PHP en Foros del Web. Holas. He cojido este codigo desde los aportes de tutorial, pero cuando lo hecho andar, me sube la imagen a la carpeta upload pero a ...
  #1 (permalink)  
Antiguo 11/04/2009, 17:15
 
Fecha de Ingreso: marzo-2009
Mensajes: 20
Antigüedad: 15 años, 1 mes
Puntos: 0
problemas con tutorial para subir varias imagenes a la vez

Holas.
He cojido este codigo desde los aportes de tutorial, pero cuando lo hecho andar, me sube la imagen a la carpeta upload pero a continuacion me dice los errores siguientes:

Código HTML:
Imagen01.jpg Subido con Exito
Notice: Undefined offset: 1 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 27
Notice: Undefined offset: 1 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 28
Notice: Undefined offset: 1 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 29
Notice: Undefined offset: 1 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 30
Notice: Undefined offset: 2 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 27
Notice: Undefined offset: 2 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 28
Notice: Undefined offset: 2 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 29
Notice: Undefined offset: 2 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 30
Notice: Undefined offset: 3 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 27
Notice: Undefined offset: 3 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 28
Notice: Undefined offset: 3 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 29
Notice: Undefined offset: 3 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 30
Notice: Undefined offset: 4 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 27
Notice: Undefined offset: 4 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 28
Notice: Undefined offset: 4 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 29
Notice: Undefined offset: 4 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 30
Notice: Undefined offset: 5 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 27
Notice: Undefined offset: 5 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 28
Notice: Undefined offset: 5 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 29
Notice: Undefined offset: 5 in C:\EasyPHP 3.0\www\CPA. v.5\subearchivo.phtml on line 30
El codigo sacado es el siguiente:

Código PHP:
<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>
Alguien sabe que son estos errores?,dichas lineas son los de $archivo;$tamanio;$tipo;$nombre.

Se podra usar este mismo codigo para subir las imagenes a la base de datos en vez que a la carpeta??

De antemano muchas gracias
  #2 (permalink)  
Antiguo 11/04/2009, 18:28
Avatar de David
Moderador
 
Fecha de Ingreso: abril-2005
Ubicación: In this planet
Mensajes: 15.720
Antigüedad: 19 años
Puntos: 839
Respuesta: problemas con tutorial para subir varias imagenes a la vez

Significa que los índices 1, 2, 3, 4 y 5 de $_FILES['archivo']['*'] no existe. Podrías usar isset() para evitar esas advertencias:
Código php:
Ver original
  1. if (isset($_FILES['archivo']['name'][$j])) {
  2.     // Copiar archivo
  3. }
__________________
Por favor, antes de preguntar, revisa la Guía para realizar preguntas.
  #3 (permalink)  
Antiguo 11/04/2009, 20:30
 
Fecha de Ingreso: marzo-2009
Mensajes: 20
Antigüedad: 15 años, 1 mes
Puntos: 0
Respuesta: problemas con tutorial para subir varias imagenes a la vez

OK... David,
He modificado este codigo para que pueda subirme a la base de datos un nombre un titulo y de 1 a 6 imagenes, pero al ejecutarlo me repite las imagenes, osea, en vez que me quede en la BD "titulo/autor/imagen1/imagen2/imagen3", la sentencia me da el siguiente resultado: "titulo/autor/imagen1/imagen1/imagen1"
"titulo/auor/imagen2/imagen2/imagen2"
"titulo/autor/imagen3/imagen3/imagen3"

Les envio el codigo para ver que estoy ejecutando mal, de antemano GRACIAS

Código PHP:
if (isset($_POST['Submit2'])){
$cantidad2 =count($_FILES['archivo']);
for (
$j=0;$j<=$cantidad2;$j++){
$unique time();
$uploadfile $_FILES['archivo']['name'][$j];
$uploadcheck $uploadfile;
                        
if(empty(
$_FILES['archivo']['name'][$j])){
$uploadfile "";
                                                                                             }
$x=$j;
                                         
do
{
$x++;
                                    
if( 
$uploadfile != "" ){
$update mysql_db_query("$dbname","INSERT INTO imagenes VALUES ('$nov_titulo', '$nov_autor', '$uploadfile', '$uploadfile','$uploadfile')") or die(mysql_error());
{
echo 
$uploadfile." Subido con Exito<br>";
}
}
}while(
$x<$j);
}

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 14:40.