Ver Mensaje Individual
  #1 (permalink)  
Antiguo 07/02/2014, 15:47
taoshi
 
Fecha de Ingreso: julio-2009
Mensajes: 117
Antigüedad: 14 años, 10 meses
Puntos: 0
Forzar descargas en php

Buenas estoy con el siguiente script el cual parece estar bastante extendido por la red

Código PHP:
<?php

if (!isset($_GET['file']) || empty($_GET['file'])) {
 exit();
}
$root "usuarios/" $_GET['user'] . "/rutas/";
$file "nuevastarifas.rar"/*basename($_GET['file'])*/;
$path $root.$file;
$type '';

if (
is_file($path)) {
 
$size filesize($path);
 if (
function_exists('mime_content_type')) {
 
$type mime_content_type($path);
 } else if (
function_exists('finfo_file')) {
 
$info finfo_open(FILEINFO_MIME);
 
$type finfo_file($info$path);
 
finfo_close($info);
 }
 if (
$type == '') {
 
$type "application/force-download";
 }
 
// Definir headers
header("Content-Type: $type");
header("Content-Disposition: attachment; filename=$file");
header("Content-Transfer-Encoding: binary");
header("Content-Length: " $size);
ob_clean();
flush();
// Descargar archivo
readfile($path);
} else {
 die(
"El archivo no existe.");
}
    
?>
Mi problema es que ponga el tipo de archivo que ponga siempre me lo abre en el navegador en ningún caso lo descarga.

Si alguien tiene una solución o un script mejor que lo diga.

Gracias.


Edito--->> mi versión de php es 5.4 y mi hosting es 1and1, por si sirve de ayuda.

Última edición por taoshi; 07/02/2014 a las 17:28