Ver Mensaje Individual
  #1 (permalink)  
Antiguo 01/06/2013, 19:26
edward18_1
 
Fecha de Ingreso: septiembre-2011
Mensajes: 480
Antigüedad: 12 años, 8 meses
Puntos: 18
Descargar archivos con php

Hola, intento descargar archivos con el php...lo cual hago la descarga y me aparece el archivo con todo y el nombre con el cual esta en mi servidor (NO LOCAL) pero simplemente cuando la reviso propiedades..dice 0kb pero si descarga el archivo con todo y su nombre y extension! pero dice 0Kb y no abre en lo absoluto claro esta! este es el codigo que tengo

Código PHP:
Ver original
  1. <?php session_start();
  2. if(isset($_SESSION['admin'])){
  3. if(isset($_GET['id_mens'])){   
  4. if(is_numeric($_GET['id_mens'])){  
  5. $id_yo=$_SESSION['mi_id'];
  6. $id_mens=isset($_GET['id_mens']) ? $_GET['id_mens'] : NULL;
  7. $consulta=("SELECT archivo FROM mensajes WHERE id_mensaje='$id_mens' AND (id_envia='$id_yo' OR id_recibe='$id_yo')  ");
  8. $pr=mysql_query($consulta) or die(mysql_error());
  9. if(mysql_num_rows($pr)<=0){
  10. }else{
  11. while($or=mysql_fetch_array($pr)){ 
  12. if (empty($or['archivo'])) {
  13. exit();
  14. }
  15. $root = "../arc/";
  16. $file = basename($or['archivo']);
  17. $path = $root.$file;
  18. $type = '';
  19. if (is_file($path)) {
  20. $size = filesize($path);
  21. if (function_exists('mime_content_type')) {
  22. $type = mime_content_type($path);
  23. } else if (function_exists('finfo_file')) {
  24. $info = finfo_open(FILEINFO_MIME);
  25. $type = finfo_file($info, $path);
  26. finfo_close($info);
  27. }
  28. if ($type=='') {
  29. $type = "application/force-download";
  30. }
  31. header("Last-Modified: " . gmdate("D, d M Y H:i:s T", filemtime($path)));
  32. header("Pragma: no-cache");
  33. header("Expires: 0");
  34. header("Content-Transfer-Encoding: binary");
  35. header("Content-type: ".mime_content_type($path));
  36. header("Content-Disposition: attachment; filename=$path");
  37. $fp = fopen($path,'rb');
  38. if ( !$fp ) {
  39.     echo "Error al abrir";
  40.     exit();
  41. }
  42. if ( !fpassthru($fp) ) {
  43.     echo "Error al enviar";
  44.     exit();
  45. }
  46. header("Connection: close");
  47. exit();  
  48. }else{
  49. die("El archivo no existe.");}}}}}}?>
__________________
Para el logro del triunfo siempre ha sido indispensable pasar por la senda de los sacrificios. Simon Bolivar