Stef Geysels
Stef Geysels

Reputation: 1047

Readfile displays content

When i use following headers, IE7 shows me the content of the file, not a download prompt. I searched al over google but didn't find an expanation.

header('Content-Description: File Transfer');
header('Content-Type: application/force-download');
header('Content-Disposition: attachment; filename=\"Copy van '.basename($file).'\"');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); 
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;

Upvotes: 0

Views: 560

Answers (1)

Stef Geysels
Stef Geysels

Reputation: 1047

When you want to send headers, be sure they are the first output of your script.

this won't work:

<html>  //==>output buffer
echo ... //==>output buffer
<?php header(...) ?>

this works:

<?php
session_start();
$some_variable=$_POST[];
$k="2";
//until here, nothing is send to the output buffer
header(...);
?>
<html>

Upvotes: 1

Related Questions