Ver Mensaje Individual
  #1 (permalink)  
Antiguo 08/02/2009, 23:37
Avatar de jpunk
jpunk
 
Fecha de Ingreso: octubre-2005
Ubicación: Bogota
Mensajes: 335
Antigüedad: 18 años, 5 meses
Puntos: 0
Sonrisa Error al subir n imagenes al servidor?

Alguien me puede ayudar a completar el código para subir n imágenes al servidor.
No se como enviarlas, veo me toma la cantidad de imágenes que intento subir pero no logro enviarlas con éxito al servidor.

Alguien me puede explicar como colocar la ruta ya que eso debe ser mi error.

Código PHP:
<?php

$postback 
= isset($_POST) ? true false;

if(
$postback) {
    
$archivos '';
    
    if(isset(
$_FILES['archivos'])) {  // Si es que subio algun archivo
        
//        $cantidad =count($_FILES["archivos"]);
//        echo 'Se enviaron: '.$cantidad.' archivos'; 

        
$cantidad 0;
        foreach(
$_FILES['archivos']['error'] as $key => $error) {  // itera sobre la coleccion de archivos
             
$cantidad++;
             
             if(
$error == UPLOAD_ERR_OK){
                 echo 
'valor $key='.$key."<br />";
             }
            
/*
            if($error == upload_err_ok) {  // si no hay error
                $tmp_name = $_FILES["archivos"]["tmp_name"][$key];
                $name = $_FILES["archivos"]["name"][$key];
                $name = uniqid('bc').'_'.$name;  // Genera un nombre unico para el archivo
                
//                move_uploaded_file($tmp_name, $_SERVER['DOCUMENT_ROOT']."./pruebas/imagenes/"); // Guardamos el archivo en una ubicacion
            }
            */ 
        
}
        echo 
'Cantidad de archivos:'.$cantidad;
    }
}
    
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Multiple Upload</title>
<style type="text/css">
/* mostrar bien los nuevos elementos */
.file{
display:block;
}
span a{
margin-left:1em;
}

input, textarea{
border:3px double #CCC;
background-color:#FAFAFA;
}
</style>
<script type="text/javascript">
var numero = 0;

// Funciones comunes
c= function (tag) { // Crea un elemento
   return document.createElement(tag);
}
d = function (id) { // Retorna un elemento en base al id
   return document.getElementById(id);
}
e = function (evt) { // Retorna el evento
   return (!evt) ? event : evt;
}
f = function (evt) { // Retorna el objeto que genera el evento
   return evt.srcElement ?  evt.srcElement : evt.target;
}

addField = function () {
   container = d('files');

   span = c('SPAN');
   span.className = 'file';
   span.id = 'file' + (++numero);

   field = c('INPUT');
   field.name = 'archivos[]';
   field.type = 'file';

   a = c('A');
   a.name = span.id;
   a.href = '#';
   a.onclick = removeField;
   a.innerHTML = 'Quitar';

   span.appendChild(field);
   span.appendChild(a);
   container.appendChild(span);
}
removeField = function (evt) {
   lnk = f(e(evt));
   span = d(lnk.name);
   span.parentNode.removeChild(span);
}
</script>
</head>

<body>
 <form name="frm" id="frm" action="" method="post" enctype="multipart/form-data">
   <dl>
     <dt>
       <label>Archivos Adjuntos</label>&nbsp;&nbsp;
         <a href="#" onclick="addField()">anadir archivo</a>
     </dt>
     <dd>
       <div id="files">         
         
       </div>
     </dd>
     <dd>
       <input type="submit" value="Enviar" id="postback" name="postback" />
     </dd>
   </dl>
 </form>
</body>
</html>