Downloading a file via HTTPS using PHP

Here is some information on how to download a file over an HTTPS connection from PHP. This normally is not a big issue in both IE and Mozilla for HTTP but changing to a HTTPS connection breaks using IE for downloading.

For anyone looking at this issue of http vs https downloads I found that the only change I had to make to my working script was to add the header line:

header("Pragma: cache");


So my script ended up with the following:

Header("Pragma: cache");
Header("Content-Type: {$filetype}");
Header("Content-Disposition: attachment; filename={$filename}");
Header("Content-Description: downloaded from {$path}");

readfile($filewithpath); // or "echo $contents;" depending on what you want to spit out


Both Mozilla and IE6 now work in both http and https.