I'm just learning PHP, and I'm having a problem using fpassthru(). I
want to download a file using the following code segment I found,
which I put into my testing file called portal.php:
$fileString = './' . $params[1];
// translate file name properly for Internet Explorer.
if ( strstr( $_SERVER['HTTP_USER_AGEN T'], "MSIE" )) {
$params[1] = preg_replace( '/\./', '%2e', $params[1],
substr_count($p arams[1], '.') - 1 );
}
header( "Cache-Control: " ); // leave blank for IE
header( "Pragma: " ); // leave blank for IE
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=\"" .
$params[1] . "\"" );
header( "Content-length:" . (string)(filesi ze( $fileString )));
sleep(1);
$fdl = @fopen( $fileString, 'rb' );
fpassthru( $fdl );
However, when I run it, I get the following:
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 178
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 179
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 180
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 182
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 183
The contents of the file I am trying to download (an html file) is
then displayed, interpreted as if it were appended to the end of
portal.php. Does anyone know what is causing this, and how I can fix
it? Thanks in advance to all who respond.
want to download a file using the following code segment I found,
which I put into my testing file called portal.php:
$fileString = './' . $params[1];
// translate file name properly for Internet Explorer.
if ( strstr( $_SERVER['HTTP_USER_AGEN T'], "MSIE" )) {
$params[1] = preg_replace( '/\./', '%2e', $params[1],
substr_count($p arams[1], '.') - 1 );
}
header( "Cache-Control: " ); // leave blank for IE
header( "Pragma: " ); // leave blank for IE
header( "Content-type: application/octet-stream" );
header( "Content-Disposition: attachment; filename=\"" .
$params[1] . "\"" );
header( "Content-length:" . (string)(filesi ze( $fileString )));
sleep(1);
$fdl = @fopen( $fileString, 'rb' );
fpassthru( $fdl );
However, when I run it, I get the following:
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 178
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 179
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 180
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 182
Warning: Cannot modify header information - headers already sent
by (output started at /export/home/.../portal.php:26) in
/export/home/.../portal.php on line 183
The contents of the file I am trying to download (an html file) is
then displayed, interpreted as if it were appended to the end of
portal.php. Does anyone know what is causing this, and how I can fix
it? Thanks in advance to all who respond.
Comment