EnglishFrenchGerman Spain Italian Dutch Russian Portuguese Japanese Korean Arabic Chinese Simplified

Subir ficheros desde tu PC - php


Instrucciones: Configurar el archivo config.php
codigo 1 index.php
<?php
//index.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></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="50%" 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>

codigo 2 enviar.php
<?php
//enviar.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_archivos, 0777);
}
# 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
  header("Location: index.php");
 }
 else
  header("Location: index.php?errno=1&errmsg=Su archivo excede los ".$bytes_max."bytes.");
}
else
 header("Location: index.php?errno=1&errmsg=No ah seleccionado ningun archivo.");
?>

codigo 3 config.php
<?php
//config.php
# Nombre carpeta de archivos
$carpeta_archivos = 'archivos';
# Maximo Bytes
$bytes_max = '500';
?> 


0 Responses So Far:

web-xtreme.blogspot.com. Con la tecnología de Blogger.