elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Estamos en la red social de Mastodon


+  Foro de elhacker.net
|-+  Programación
| |-+  Desarrollo Web
| | |-+  PHP (Moderador: #!drvy)
| | | |-+  forzar descarga archivo php
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: forzar descarga archivo php  (Leído 5,482 veces)
kakashi20


Desconectado Desconectado

Mensajes: 435


Ver Perfil
forzar descarga archivo php
« en: 7 Septiembre 2009, 17:38 pm »

hola
yo tengo este par de codigos para subir y listar archivos en php

upload.php

<?php
$status = "";

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>PHP upload - unijimpe</title>
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="413" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="413" height="40" class="titulo">Cargar Achivos </td>
  </tr>
  <tr>
    <td class="text">Por favor seleccione el archivo a subir:</td>
  </tr>
  <tr>
  <form action="lista.php" method="post" enctype="multipart/form-data">
    <td class="text">
      <input name="archivo" type="file" class="casilla" id="archivo" size="35" />
      <input name="enviar" type="submit" class="boton" id="enviar" value="Subir Archivo" />
     <input name="action" type="hidden" value="upload" />     </td>
   </form>
  </tr>
  <tr>
    <td class="text" style="color:#990000"><?php echo $status; ?></td>
  </tr>
  <tr>
    <td height="30" class="subtitulo">Listado de Archivos Subidos </td>
  </tr>
  <tr>
    <td class="infsub">
   <?php
   /*if ($gestor = opendir('archivos')) {
      echo "<ul>";
       while (false !== ($arch = readdir($gestor))) {
         if ($arch != "." && $arch != "..") {
            echo "<li><a href=\"archivos/".$arch."\" class=\"linkli\">".$arch."</a></li>\n";
         }
       }
       closedir($gestor);
      echo "</ul>";
   }*/
   ?>   </td>
  </tr>
</table>
</body>
</html>

lista.php

<?php
   
$status = "";
 
if ($_POST["action"] == "upload") {
   // obtenemos los datos del archivo
   $tamano = $_FILES["archivo"]['size'];
   $tipo = $_FILES["archivo"]['type'];
   $archivo = $_FILES["archivo"]['name'];
   $prefijo = substr(md5(uniqid(rand())),0,6);
   
   if ($archivo != "") {
      // guardamos el archivo a la carpeta files
      $destino =  "archivos/".$prefijo."_".$archivo;
      if (copy($_FILES['archivo']['tmp_name'],$destino)) {
         $status = "Archivo subido satisfactoriamente: <b>".$archivo."</b>";
      } else {
         $status = "Error al subir el archivo";
      }
   } else {
      $status = "Error al subir archivo";
   }
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="estilo.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
   echo "".$status;
?>   
<table>
<tr>
    <td height="30" class="subtitulo">Listado de Archivos Subidos </td>
  </tr>
  </table>
   <?php
   
   if ($gestor = opendir('archivos')) {
      echo "<ul>";
       while (false !== ($arch = readdir($gestor))) {
         if ($arch != "." && $arch != "..") {
            echo "<li><a href=\"archivos/".$arch."\" class=\"linkli\">".$arch."</a></li>\n";
            echo"<a href='eliminar_archivo.php?nom=".$arch."'>eliminar</a>";
         
         }
       }
       closedir($gestor);
      echo "</ul>";
      
   }
   echo "<br><br>";
   echo"<a href='upload.php>Regresar a Upload</a>";
   
   

   ?>   </td>

</body>
</html>


mi pregunta es :

como hago para forzar la descarga de estos archivos listados ?

agredeceria la ayuda


En línea

дٳŦ٭
GNU/Linux Infrastructure Specialist
Ex-Staff
*
Desconectado Desconectado

Mensajes: 5.110


Ver Perfil WWW
Re: forzar descarga archivo php
« Respuesta #1 en: 7 Septiembre 2009, 18:31 pm »

Código
  1. $id = "wallpaper_02_04.jpg";
  2. $enlace = $path."/".$id;
  3. header ("Content-Disposition: attachment; filename=".$id."\n\n");
  4. header ("Content-Type: application/octet-stream");
  5. header ("Content-Length: ".filesize($enlace));
  6. readfile($enlace);
  7.  

Suerte


En línea

kakashi20


Desconectado Desconectado

Mensajes: 435


Ver Perfil
Re: forzar descarga archivo php
« Respuesta #2 en: 7 Septiembre 2009, 19:46 pm »

funciona. pero cuando guardo el archivo en el pc y lo abro dice que no se puede abrir porque el archivo esta dañado.....
En línea

Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

Mensajes similares
Asunto Iniciado por Respuestas Vistas Último mensaje
como forzar la descarga de ficheros de extensiones multiples con PHP?
PHP
hack-4-life 0 3,726 Último mensaje 15 Octubre 2011, 06:59 am
por hack-4-life
Recuperar descarga desde archivo.part
Dudas Generales
79137913 0 2,056 Último mensaje 21 Junio 2012, 19:15 pm
por 79137913
forzar descarga pdf
PHP
kakashi20 1 3,380 Último mensaje 27 Noviembre 2012, 10:44 am
por dimitrix
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines