Ver Mensaje Individual
  #4 (permalink)  
Antiguo 08/02/2006, 07:53
Avatar de carlosfocus
carlosfocus
 
Fecha de Ingreso: enero-2006
Ubicación: Venezuela
Mensajes: 823
Antigüedad: 18 años, 3 meses
Puntos: 0
Prueba Este

config.php


Código PHP:


<?php



# Nombre carpeta de archivos
$carpeta_archivos '../Images/webcms/';
# Maximo Bytes
$bytes_max '500000';

?>


Subir.php

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>

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 mejor 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

    
}
    else
 echo  
"Error al Subir";
 echo 
"<br>";
 echo  
"Su archivo excede los  ".$bytes_max." Bytes ";
#        header("Location: index.php?errno=1&errmsg=Su archivo excede los ".$bytes_max."bytes.");
}
else

# echo  "Error al Subir";

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

?>


Espero te sirva a mi me funciona perfectamente
__________________
Carlos Herrera
Web Developer
www.carlos.com.ve
Para descargar archivos propios a su Teléfono Mobil? www.carlosfocus.com