Ver Mensaje Individual
  #1 (permalink)  
Antiguo 23/02/2006, 12:08
albertt_t
 
Fecha de Ingreso: noviembre-2004
Mensajes: 159
Antigüedad: 19 años, 5 meses
Puntos: 0
Exclamación Problema con upload

saludos Amigos tengo este script de upload de ficheros que consta de 3 archivos config, formulario y enviar (todos php)

El detalle es que no me valida el peso del archivo y tampoco en el caso de no haber seleccionado algun archivo tampoco me lo valida... simplemente siempre me sale el mensaje de ok!! a pesar de haber usado un if y un else!

gracias

A. Acosta.


config.php

Código PHP:

<?php 



# Nombre carpeta de archivos 
$carpeta_archivos 'files/'
# Maximo Bytes 
$bytes_max 500000

?>

Enviar.php
Código PHP:







<?php 



include("config.php"); 

# Si la carpeta no existe la creamos y le aplicamos los permisos. 
if(!file_exists($carpeta_archivos)) 

    
mkdir($carpeta_archivos); 
    @
chmod($carpeta_archivos0777); 


# Verificamos que este setiado el archivo. 

if($_FILES['archivo']) 

    { 
        
# Verificamos que su tamaño sea menor que los bytes que as puesto en la configuración. 
    
        
if((1000 $bytes_max) > $_FILES['archivo']['size']) 
    
            { 
        
            
# Seteamos las variables para mejor facilidad 
            
                
$tmp $_FILES['archivo']['tmp_name']; 
            
$name $_FILES['archivo']['name']; 
            
$ahora $carpeta_archivos.'/'.$name
         
            
# Movemos el archivo a la carpeta 
            
move_uploaded_file($tmp$ahora); 
         
               
# Nos movemos al index.php 
    
            
echo  "Ok su archivo ha sido subido exitosamente gracias";
             
            } 
    
    else 
     
        echo  
"Su archivo excede los  ".$bytes_max." Bytes ";
    
   }
        
                    
else 

        {

         echo  
"Error al Subir"

        
header("Location: index.php?errno=1&errmsg=No ah seleccionado ningun archivo."); 

        }

?>


Formulario


Código PHP:
<?php 


# Mensaje por defecto. 
$defecto 'Eliga el archivo a subir y presione el boton Enviar!.'

# Seteamos la variable $msg con un if  
# $variable = (exp) ? true : false; 
$msg = ($_GET['errno']==1) ? $_GET['errmsg'] : $defecto

?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> 
<html> 

<head> 
    <title>subir archivos</title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <style type="text/css"> 
        body, table { 
            background-color: #f2f2f2; 
            font-family: tahoma; 
            font-size: 10px; 
        } 
         
        input { 
            background-color: #FFFFFF; 
            border: 1px solid #000000; 
            font-family: tahoma; 
            font-size: 10px; 
        } 
    </style> 
</head> 

<body> 

<form method="post" enctype="multipart/form-data" action="enviar.php"> 
     
  <table width="100%" style="margin: auto;"> 
    <tr> 
            <td colspan="2" style="width: 100%;"><b><?=$msg?></b></td> 
        </tr> 
        <tr> 
            <td style="width: 45%;">(1) Elegir Archivo:</td> 
            <td style="width: 55%;"><input type="file" name="archivo" size="20" /></td> 
        </tr> 
        <tr> 
            <td style="width: 45%;">(2) Enviar Archivo:</td> 
            <td style="width: 55%;"><input type="submit" value="Enviar!" /></td> 
        </tr> 
    </table> 
</form> 

</body> 

</html>