Ver Mensaje Individual
  #1 (permalink)  
Antiguo 06/11/2014, 15:39
evoarte
 
Fecha de Ingreso: julio-2002
Mensajes: 813
Antigüedad: 21 años, 9 meses
Puntos: 2
forzar descarga de archivos con php y seguridad

buenas noches,

he puesto la posibilidad de descargar archivos en una web, y me gustaría saber si es segura:

Código HTML:
Ver original
  1. <a href="http://www.nombredelaweb.com/ruta/descarga.php?archivo=<%=archivos[j][2]%>&ubicar=correou"><%=archivos[j][2]%></a>

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

un saludo.