Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/01/2008, 08:46
onZero
 
Fecha de Ingreso: diciembre-2007
Mensajes: 75
Antigüedad: 16 años, 5 meses
Puntos: 0
Re: Programa que suba ficheros al servidor indicandole la ruta?

yo hize hace tiempo uno... bueno aca te lo paso....
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=iso-8859-1" />
<title>Subir archivos</title>
</head>
<body>
<h1>Subir Archivos...</h1>
<?
if(isset($_FILES['archivo']))
{
   
$dir='archivos';
   
$fexplode("/"$_SERVER['PHP_SELF']);
   
$fichero=$f[count($f)-1];
   
$url=$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'];
   
$url"http://".str_replace($fichero""$url);
   if(!
is_dir($dir))
   {
   @
mkdir($dir);
   }
   
$archivo=$_FILES['archivo'];
      if(
ereg("pdf"$archivo['type']))
      {
         
$b=pathinfo(strtolower($archivo['name']));
         
         do{
            
$name="archivo".rand().".".$b['extension'];
         }while(
file_exists($dir."/".$name);

         
$a=move_uploaded_file($archivo['tmp_name'], $dir."/".$name);
         if(
$a){
         
$exito='Se a  subido exitosamente el archivo';
         }
         else{
         
$error='No se ha logrado subir';
         }
      }
      else{
      
$error='La extencion del archivo es incorrecta';
      }
}
if(!isset(
$exito))
{
?>
<form action="#" method="post" enctype="multipart/form-data" name="form_subir" id="form_subir">
    <input type="file" name="archivo" />
    </label>
  </p>
  </p>
  <?
  
if(isset($error))
  {
  echo 
"<br>".$error;
  }
  
?>
  <br />
    <label>
    <input type="submit" name="Submit" value="Upload Image" />
    </label>
</form>
  <?
}
else
{
?>
<form id="form2" name="form2" method="post" action="">
  <label>Enlace directo
  <input name="textfield" type="text" value="<?=$url.$dir."/".$name?>" size="75" />
  </label>
</form>
 <?
}
?>
</body>
</html>
la carpeta esta definida por $dir

Última edición por onZero; 10/01/2009 a las 11:25