Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/02/2011, 15:15
kirst
 
Fecha de Ingreso: septiembre-2009
Mensajes: 230
Antigüedad: 17 años
Puntos: 2
Problema al subir imagenes superiores a 1mb

En mi input type file, cuando selecciono imagenes grandes, quiero decir, mayores a 1mb, 2mbs, 5mb fue mi maximo, es como si volviera al principio del form, no recibo variables del _POST files, tampoco variables personalizadas que puse de $error, nada, que puede ser? Utilizo php y el form en una plantilla php para hacerlo :S


Código PHP:
<form action="<?= $upload_form ?>" method="post" enctype="multipart/form-data">
      Imágenes a subir: <select name="cantidad">
                    <script type="text/javascript">
                    for(x=1;x<=20;x++){
                    document.write("<option value="+ x +">"+ x+"</option>");
                    }
                    </script>
      </select>
      <input type="submit" name="OK" value="OK"><br />      
+ No deberán pesar más de 8MBytes.<br />
+ Deberán ser: JPG, PNG O GIF.<br /><br />
<?php    
if(isset($_POST['OK'])){
        echo 
"Elegir Im&aacute;genes para Subir<br />";
            for(
$i=1;$i<=$_POST['cantidad'];++$i){
                echo 
"<input type=\"file\" name=\"archivo[]\"><br>";
            }
    if(empty(
$_GET['album'])) {
        echo 
"<label for=\"album\">Nombre del Album:</label> <input type=\"text\" name=\"album\" size=\"20\" /><br />";
         } else {
        echo 
"<label for=\"album\">Nombre del Album:</label> <input type=\"text\" name=\"album\" size=\"20\" value=".$_GET['album']." /><br />";
                 }
        echo 
"<input type=\"submit\" name=\"SUBIR\" value=\"Subir\">";
        echo 
"<input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"52428800\" />";
        echo 
"<input type=\"hidden\" name=\"cant1\" value=\"$i\">";
    }
    
    if(isset(
$_POST['SUBIR'])){
        
$cantidad2 =count($_FILES["archivo"]);
        
$album = $_POST['album'];        
        
        
$partes = explode(".", $nombre); 
        
$extencion = end($partes); 
        
        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];
                
// Explode para saber la extencion del archivo
                
$partes = explode(".", $nombre); 
                
$extencion = end($partes); 

                
        if (! (
$extencion == 'jpg' or $extencion == 'JPG' or $extencion == 'png' or $extencion == 'PNG' or $extencion == 'gif' or $extencion == 'GIF') ) 
            
$error['tipo'] = 'La imagen no concuerda con los tipos permitidos.'; 
        
            
        if (
$tamanio >= 8388608)
            
$error['peso'] = 'El archivo excede el tamaño de 8MBytes. Tiene que pesar menos.';

        if (empty(
$album))
            
$error['album'] = 'El Album tiene que tener un nombre.';
            
             
$x=$j;
             do{
             
$x++;
                if( 
$archivo != "" ){
                    if(empty(
$error)) {
                           
$fp = fopen($archivo, "rb");
                           
$contenido = fread($fp, $tamanio);
                           
$contenido = addslashes($contenido);
                           
fclose($fp);
                           
//AQUI  INSERTE EN LA BASE DE DATOS
                           
                           // Creo la carpeta del album!
                           
if (is_dir($upload_folder.$_SESSION['nickname'].'/'.$album) == FALSE) {
                           
mkdir ($upload_folder.$_SESSION['nickname'].'/'.$album);
                           }
                           
                           
// Le doy un valor RANDOM al nombre del archivo para evitar errores
                           
$randomtext = substr(md5(uniqid(rand())),0,6);
                           
                           
// Le doy la ruta de subida
                           
$uploaddir=$upload_folder.$_SESSION['nickname'].'/'.$album."/";
                           
                           
// Sacamos caracteres especiales al archivo subido por si es un script malicioso
                           
$nombre = htmlspecialchars($nombre);
                           
                           
// Empiezo el proceso para achivar el tamaño y dimensiones de la imágen
                            //$maxsize += 8;
                            
list($width, $height) = getimagesize("$archivo");
                            if(
$width > '720') $width = '720';
                            elseif(
$width <= '720') $width = $width;
                            if(
$height > '540') $height = '540';
                            elseif(
$height <= '540') $height = $height;
                            
//$width = min($width, $height);
                            
$tn = imagecreatetruecolor($width, $height);
                            
$image = imagecreatefromjpeg("$archivo");
                            
imagecopyresampled($tn, $image, 0, 0, 0, 0, $width, $height, $width, $height);
                            
                           
//if(copy($archivo, $uploaddir.$randomtext.'_'.$nombre))
                           
if(imagejpeg($tn, $uploaddir.$randomtext.'_'.$nombre, 90))
                                {
                                   echo 
"<b>Subida con Exito:</b> ".$nombre."<br />";
                                   
$subida = true;
                                }
                           }
                        } 
//if
                    
}
                    while(
$x<$j); }
             }
        
?>
    <? if (!empty($error) && $subida != true) { ?>        <? foreach ($error as $mensaje) { ?>
            <br />+ <?= $mensaje ?>
        <? } ?>
    <? } ?>
</form>