Tema: upload php
Ver Mensaje Individual
  #1 (permalink)  
Antiguo 05/03/2010, 11:04
willhemsv
 
Fecha de Ingreso: febrero-2008
Mensajes: 79
Antigüedad: 16 años, 2 meses
Puntos: 1
upload php

Amigos del foro, estoy haciendo un upload en php y tengo el siguiente problema, va todo bien hasta el momento en que se debe dejar el archivo en el dir de destino. me discrimina extension, tamaño y pasa el check del directorio, pero siempre me da el ultimo mensaje de error "There was an error during the file upload. Please try again."

Para que me puedan ayudar les dejo el código de ambos archivos. saludos y de antemano gracias.

form.php
Código PHP:
<!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=utf-8" />
<
title>Suba Sus Imagenes...</title>
<
script language="javascript" type="text/javascript">
num=0/*tenemos un valor cero que es la cantidad de type=file al cargar la pagina*/
function desac(){
        
/*este if se preocupa de bloquear el <select> cuando se marce crear nueva carpeta
        y darle al input el valor de "nombre de carpeta"*/
        
if (document.getElementById('nf').checked == true){
            
document.getElementById('folds').disabled true;
            
document.getElementById("foldname").value "Nombre Carpeta";
            
document.getElementById("foldname").disabled false;
        }
    }
function 
act(){
        
/*Este if hace lo propio al marcar subir a carpeta antigua*/
        
if (document.getElementById('nf').checked == false){
            
document.getElementById('folds').disabled false;
            
document.getElementById("foldname").disabled true;
        }
        }
function 
crear(obj) {/*funcion para crear los type=file*/
  
if (num <= 9){
  
num++;
  
fi document.getElementById('fiel'); // 1
  
contenedor document.createElement('div'); // 2
  
contenedor.id 'div'+num// 3
  
fi.appendChild(contenedor); // 4

  
ele document.createElement('input'); // 5
  
ele.type 'file'// 6
  
ele.name 'fil'+num// 6
  
contenedor.appendChild(ele); // 7
  
  
ele document.createElement('input'); // 5
  
ele.type 'button'// 6
  
ele.value 'Borrar'// 8
  
ele.name 'div'+num// 8
  
ele.onclick = function () {borrar(this.name)} // 9
  
contenedor.appendChild(ele); // 7
  
document.getElementById("van").value "Se Subirán " num " foto(s)";
  }
    }
/*fin funcion creadora de type=file*/
function borrar(obj) {/*funcion para borrar type=file*/
  
num--;
  
fi document.getElementById('fiel'); // 1 
  
fi.removeChild(document.getElementById(obj)); // 10
  
document.getElementById("van").value "Se Subirán " num " foto(s)";
}
function 
del(){/*esta funcion borra el texto "nombre Carpeta" al hacer click en ella*/
    
if(document.getElementById("foldname").value == "Nombre Carpeta"){
        
document.getElementById("foldname").value "";
    }
}
</script>
</head>
<body>
<p>Seleccione si subir las fotos y crear una carpeta o subirlas a una carpeta existente.</p>
<p><form name="subir" id="subir" action="upload.php" enctype="multipart/form-data" method="post">
  <input type="radio" name="selector" id="of" value="1" onchange="act()"/>
  Seleccionar Carpeta <select name="selfold" id="folds">
                          <option>Carpeta 1</option>
                        <option>Carpeta 2</option>
                        </select>
  <input type="radio"  name="selector" id="nf" value="1" onchange="desac()"/>
  Crear Carpeta <input type="text" name="foldname" id="foldname" value="Nombre Carpeta" onclick="del()"/> </p>
<input type="button" value="Sumar Foto"  onclick="crear(this)" />
<input type="text" id="van" name="van" style="border:none; font-weight:bold" />
<p><fieldset id="fiel">
  </fieldset>
<input type="submit" name="subir" id="subir" value="Subir" />
</form>
</body>
</html> 
upload.php
Código PHP:
<?php
   
// Configuration - Your Options
      
$allowedExtensions = array("jpg","jpeg");  // These will be the types of file that will pass the validation.
      
$max_filesize 524288// Maximum filesize in BYTES (currently 0.5MB).
      
$upload_path 'testPicGalery/'// The place the files will be uploaded to (currently a 'files' directory).
 
   
$filename $_FILES['subir']['name']; // Get the name of the file (including file extension).
   
$ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
  
foreach ($_FILES as $file) { 
    if (
$file['tmp_name'] > '') { 
      if (!
in_array(end(explode("."
            
strtolower($file['name']))), 
            
$allowedExtensions)) { 
       die(
$file['name'].' is an invalid file type!<br/>'
        
'<a href="javascript:history.go(-1);">'
        
'&lt;&lt Go Back</a>'); 
      } 
    } 
  }  
 
   
// Now check the filesize, if it is too large then DIE and inform the user.
   
if(filesize($_FILES['subir']['tmp_name']) > $max_filesize)
      die(
'The file you attempted to upload is too large.');
 
   
// Check if we can upload to the specified path, if not DIE and inform the user.
   
if(!is_writable($upload_path))
      die(
'You cannot upload to the specified directory, please CHMOD it to 777.');
 
   
// Upload the file to your specified path.
          
if(move_uploaded_file($_FILES['subir']['tmp_name'],$upload_path.$filename))
           echo 
'Your file upload was successful, view the file <a href="' $upload_path $filename '" title="Your File">here</a>'// It worked.
      
else
         echo 
'There was an error during the file upload.  Please try again.'// It failed :(.
 
?>