fb@1256920766
Usuario Novato
Usuario Novato

necesito ayuda porfa al intentar de forzar la descarga de un archivo con php

<?php

$url = $_SESSION['ruta']."/".$_SESSION['archivosae'];

header ("Content-Disposition: attachment; filename=SAEREGULAR.SAE" );
header ("Content-Type: application/force-download");
readfile($url);
exit;
?>

me descarga bien el SAEREGULAR.SAE

pero el archivo al abrirlo no solo sale lo que contiene el archivo sino que contiene html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin título</title>
</head>
<body>
<p>
CZD12222286DFV6;4:H574<$^HZTOJGJ&KJ[IGZOG&TGIOUTGR&GTJXKY&HKRRU&&&&&&&&&& &&&&&&&&&&&&79689697897;78A7:89<JbL9<LdN=<=>,,,,,,,


Cuando solo deberia bajarme lo que esta debajo de la etiqueta <p>, que deberia ser esto: 

CZD12222286DFV6;4:H574<$^HZTOJGJ&KJ[IGZOG&TGIOUTGR&GTJXKY&HKRRU&&&&&&&&&& &&&&&&&&&&&&79689697897;78A7:89<JbL9<LdN=<=>,,,,,,,

Avatar Image
@man / @woman
@man / @woman

Hace ya un tiempito que no tengo necesidad de programar esta funcionalidad, en su momento experimente diversos problemas, he aqui la secuencia que me dio resultado:

// hay una larga lista de content-type, por ejemplo:
header('Content-Type:application/octet-stream'); // rar
header('Content-Type:text/plain'); // txt, html, etc

// más esto:
header('Content-Type:application/force-download');
header('Content-Description:File Transfer');
header('Pragma:public');
header('Expires:0');
header('Cache-Control:no-cache,must-revalidate,post-check=0,pre-check=0');
header('Cache-Control:private,false');
header("Content-Disposition:attachment;filename={$fn}");
header('Content-Length:'.filesize( $fn ));
@readfile( $fn );
die();

fb@1256920766
Usuario Novato
Usuario Novato

@GestionXls,

Gracias Amigo ;) el unico problema ahora es que me lo descarga bien pero solo localmente, cuando lo subo al hosting y intento descargar me sale este error:

Cita:

Warning: filesize(): stat failed for SIST_SAE/Licencias/LARA/BQTO CENTRO/SAEREGULAR.RRGG001_00000195 in /home/u997603911/public_html/plantel/diradepe/licencia.php on line 19

La verdad habia parado esta parte por mucho tiempo por no tenerle una solucion :S

Utilizo el wampserver, cuando lo corro por localhost me funciona

Cita:

<?php
include("../connect.php");
?>
<?php

$url = $_GET['hidRuta']."/".$_GET['hidArchivosae'];
// hay una larga lista de content-type, por ejemplo:
header('Content-Type:application/octet-stream'); // rar
header('Content-Type:text/plain'); // txt, html, etc

// más esto:
header('Content-Type:application/force-download');
header('Content-Description:File Transfer');
header('Pragma:public');
header('Expires:0');
header('Cache-Control:no-cache,must-revalidate,post-check=0,pre-check=0');
header('Cache-Control:private,false');
header("Content-Disposition:attachment;filename={$_GET['hidArchivosae']}");
header('Content-Length:'.filesize( $url ));
@readfile( $url );
die();
?>

Avatar Image
@man / @woman
@man / @woman

1) deberías buscar e identificar la línea 19 de licencia.php

2) estimo que en ella encontrarás la instrucción que da problemas (stat, filesize u otra), puede ser que esté desactivada o algún otro factor que impide su ejecución. Revisa la lista de funciones deshabilitadas y las librerías conque se compiló el Php que esté utilizando ese hosting.

ATENCIÓN: Este tema no tiene actividad desde hace más de 6 MESES,
te recomendamos abrir un nuevo tema en lugar de responder al actual
Opciones:
Ir al subforo:
Permisos:
TU NO PUEDES Escribir nuevos temas
TU NO PUEDES Responder a los temas
TU NO PUEDES Editar tus propios mensajes
TU NO PUEDES Borrar tus propios mensajes
Temas similares
TemaUsuariosRespuestasVisitasActividad
Por: , el 16/Mar/2004, 13:30
tonait NoSetup.org716kMar/04
Por: , el 18/Ene/2011, 20:19
Pancha.S Josepepe033 NoSetup.org82kJan/11
Por: , el 16/Nov/2009, 04:41
byds Yamil_Rodriguez12kNov/09
Por: , el 24/Jun/2009, 16:33
ligoverto aerialss88 saulo123 NoSetup.org GestionXls910kNov/10
Por: , el 08/Ene/2009, 20:36
Silphor NoSetup.org43kJan/09