Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/12/2012, 12:55
matt_1985
 
Fecha de Ingreso: enero-2011
Ubicación: /root
Mensajes: 530
Antigüedad: 14 años, 2 meses
Puntos: 61
problemas con FILEINFO_MIME_TYPE

Estimados,

Tengo un problema al detectar el mime type con archivos xls y xlsx , con otro tipo de archivos funciona perfecto , lo que mi script hace es detectar el mimetype para luego asignarlo al forzar la descarga.

Código PHP:
Ver original
  1. if (is_file($path)) {
  2.     $tamano = filesize($path);
  3.     if (function_exists('FILEINFO_MIME_TYPE')) {
  4.         $tipo = FILEINFO_MIME_TYPE($path);
  5.     } else if (function_exists('finfo_file')) {
  6.         $info = finfo_open(FILEINFO_MIME_TYPE);
  7.         $tipo = finfo_file($info, $path);
  8.         finfo_close($info);
  9.     }
  10.    
  11.     //var_dump($tipo);
  12. //}  
  13.     if ($tipo == '') {
  14.         $tipo = "application/force-download";
  15.     }
  16.     // Leer cabeceras
  17.     header("Content-Type: $tipo");
  18.     header("Content-Disposition: attachment; filename=$archivo");
  19.     header("Content-Transfer-Encoding: binary");
  20.     header("Content-Length: " . $tamano);
  21.     // Descargar Archivo
  22.     readfile($path);
  23. } else {
  24.     die('El archivo que indicaste no existe!!');
  25. }

Espero , puedan ayudarme .

Saludos