Ver Mensaje Individual
  #3 (permalink)  
Antiguo 24/08/2010, 08:15
Avatar de andrewp
andrewp
 
Fecha de Ingreso: agosto-2003
Ubicación: Barcelona
Mensajes: 1.160
Antigüedad: 20 años, 8 meses
Puntos: 5
Pregunta Respuesta: Ocultar o asegurar ruta de archivo telecargable...

Gracias por tu respuesta Abimaelrc...

Finalmente he seguido tus pautas y he encontrado un tutorial bastante útil para el tema que lo transcribo aquí:

Código PHP:
Ver original
  1. <?php
  2.  
  3. if (!isset($_GET['file']) || empty($_GET['file'])) {
  4.  exit();
  5. }
  6. $root = "archivos/";
  7. $file = basename($_GET['file']);
  8. $path = $root.$file;
  9. $type = '';
  10.  
  11. if (is_file($path)) {
  12.  $size = filesize($path);
  13.  if (function_exists('mime_content_type')) {
  14.  $type = mime_content_type($path);
  15.  } else if (function_exists('finfo_file')) {
  16.  $info = finfo_open(FILEINFO_MIME);
  17.  $type = finfo_file($info, $path);
  18.  finfo_close($info);
  19.  }
  20.  if ($type == '') {
  21.  $type = "application/force-download";
  22.  }
  23.  // Definir headers
  24.  header("Content-Type: $type");
  25.  header("Content-Disposition: attachment; filename=$file");
  26.  header("Content-Transfer-Encoding: binary");
  27.  header("Content-Length: " . $size);
  28.  // Descargar archivo
  29.  readfile($path);
  30. } else {
  31.  die("El archivo no existe.");
  32. }
  33.  
  34. ?>

Sin embargo, siguiendo los pasos a rajatabla, lo que solo cargo es una especie de "layout" de la página web y no el archivo.

Esto obedece a algún problema de permisos en especial?...

Gracias.
__________________
Andrew :P