Foros del Web » Programando para Internet » PHP »

upload php

Estas en el tema de upload php en el foro de PHP en Foros del Web. 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 ...
  #1 (permalink)  
Antiguo 05/03/2010, 11:04
 
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 :(.
 
?>
  #2 (permalink)  
Antiguo 05/03/2010, 12:11
Avatar de dargor  
Fecha de Ingreso: octubre-2009
Mensajes: 134
Antigüedad: 14 años, 6 meses
Puntos: 2
Respuesta: upload php

no he revisado el código aun, pero si dices que pasa todas las condiciones, podrías verificar si donde se va a guardar el archivo tiene permisos de escritura.
  #3 (permalink)  
Antiguo 05/03/2010, 12:48
 
Fecha de Ingreso: octubre-2009
Mensajes: 43
Antigüedad: 14 años, 6 meses
Puntos: 1
Respuesta: upload php

Hola !!!

Como dice dargor, verifica que la carpeta tenga permiso de escritura, para propietario y otros.
  #4 (permalink)  
Antiguo 05/03/2010, 15:14
Avatar de dargor  
Fecha de Ingreso: octubre-2009
Mensajes: 134
Antigüedad: 14 años, 6 meses
Puntos: 2
Respuesta: upload php

bueno amigo ya probe el codigo y lo que he descubierto es que en tu archivo upload.php tenes esto:

$filename = $_FILES['subir']['name'] , pero "subir" es el la identificacion del formulario por eso es que no te esta captando ningun archivo, en cambio deberias de sustituirlo con el nombre de los controles <input type="file" name="ALGO"/> que se van generando con tu codigo de javascript.
haz la prueba haciendo un input file en la primera pagina asi a puro html, y el nombre que le pongas utilizalo en el archivo upload y veraz como trabaja.

Etiquetas: upload
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 12:25.