Jump to content

File downloads on secure server


bengaltgrs

Recommended Posts

I found the following source code for creating and downloading a file online:

 

<?php
$line1="ID\tProduct\tColor\tSales\t";
$line2="1\tPrinter\tGrey\t13\t";
$line3="2\tCD\tBlue\t15\t";
$line4="3\tDVD\tRed\t7\t";
$line5="4\tMonitor\tGreen\t4\t";
$line6="5\tTelephone\tBlack\t2\t";
$data="$line1\n$line2\n$line3\n$line4\n$line5\n$line6\n";

header("Content-type: application/x-msdownload");
header("Content-Disposition: attachment; filename=" . "extraction.xls");
header("Pragma: no-cache");
header("Expires: 0");
print "$header\n$data";

?>

 

This code works fine on a regular server, but when I tried to put it on my secure server I just got errors.  Is there a way to make this work on a secure server?

 

-Chris

Link to comment
https://forums.phpfreaks.com/topic/58342-file-downloads-on-secure-server/
Share on other sites

The file download dialog still comes up, but the filename is now 'ExportExcel_php' instead of 'extraction.xls', which is the name of the php page which is supposed to do the downloading.  Upon pressing the 'Save' button, I get an error saying "Internet Explorer cannot download ExportExcel.php. Internet Explorer was not able to open this Internet site. The requested site is either unavaliable or cannot be found. Please try again later."

This doesn't fix your proble, but instead of

$line1="ID\tProduct\tColor\tSales\t";
$line2="1\tPrinter\tGrey\t13\t";
$line3="2\tCD\tBlue\t15\t";
$line4="3\tDVD\tRed\t7\t";
$line5="4\tMonitor\tGreen\t4\t";
$line6="5\tTelephone\tBlack\t2\t";
$data="$line1\n$line2\n$line3\n$line4\n$line5\n$line6\n";

why not just do this:

$data = <<<EOF
ID	Product	Color	Sales
1	Printer	Grey	13
2	CD	Blue	15
3	DVD	Red	7
4	Monitor	Green	4
5	Telephone	Black	2

EOF;

I searched Google. Another person had a similar problem. It seemed to work if he didn't send the Pragma: no-cache header. Try to comment that line out and see if it helps.

 

A person at the PHP documentation says that IE (also IE7) is having problems with SSL downloads where the above-mentioned header is sent. Since you are using IE, have you tried another browser (Firefox, Opera, Safari, etc.)?

http://php.net/header#74876

 

The bug in IE I mentioned before is explained here: http://support.microsoft.com/kb/812935

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.