note 80882 deleted from function.session-start by peehaa
| From: | peehaa@php.net | Date: | Fri, 09 Dec 2016 22:11:36 +0000 |
| Subject: | note 80882 deleted from function.session-start by peehaa | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-208332@lists.php.net to get a copy of this message | ||
Note Submitter: cbake6807 at comcast dot net
----
Having a problem in IE causing your getFile.php script to be pushed to the browser as an empty text
file, instead of the intended attachment?
If your php config causes session_start() to output a cookie, or anything funky, IE will not like
the filename and will also try and read the file contents inline into the browser window.
Don't use session_start() or USE Output Buffering after the session is started.
<? //session_start();
function force_download($file)
{
if ((isset($file))&&(file_exists($file))) {
$fileArray = explode("/", $file);
header("Content-type: application/force-download");
header("Content-Disposition: attachment;
filename=".$fileArray[sizeof($fileArray)-1]);
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header('Content-Type: application/octet-stream');
header("Content-Disposition: attachment;
filename=".$fileArray[sizeof($fileArray)-1]);
readfile("$file");
} else {
echo "No file selected";
} //end if
}//end function
?>