Hi, 

Have installed a Turnkey LAMP appliance and new server up and running with our internal customer system written in PHP using MySQL in no time.  

However, all of our screens that force a download of a file, .ics calendar files and .vcf vcard files have now stopped working and simply display in the browser.

I know the coding works, as it worked in our old standard Unbuntu LAMP setup, works if I simply move it to a MAMP system, and works fine if I move it to any commercial LAMP hosting, such as Hostgator.

Since it worked before and works anywhere other than the Turnkey LAMP service, it means that the Turnkey LAMP has something in it's default setup that is not like anyone elses default setup. I've also tried changing my PHP code to everything suggested on the net, but nothing changes.

Given that I can move the same code literally anywhere else and it works fine, I need to find the answer quickly, as it's a real pain that it doesn't work, our staff rely on these features.

The code is very simple and is below and as I said before I get too many suggestions that the code is wrong, this code runs on any other server I use quite happily and basically makes the browser download an ics calendar file which the user can then double click on to add into their calendar.  The only place is doesn't work is on the Turnkey LAMP.  Therefore, must be a non-standard setting somewhere on Turnkey which is doing this, however have no idea where.

No combination of changing the file types makes any difference.

Help appreciated!

Code---->

 

$filename = 'job-' . $job_number . '.ics';
$mimeType = 'application/ics';
 
header('Content-Type: ' . $mimeType);
header('Content-Disposition: attachment; filename=' . $filename);
 
$addressline= $address1;
 
if ($address2) $addressline = $addressline . ", " . $address2;
if ($address3) $addressline = $addressline . ", " . $address3;
if ($address4) $addressline = $addressline . ", " . $address4;
if ($town) $addressline = $addressline . ", " . $town;
if ($county) $addressline = $addressline . ", " . $county;
if ($postcode) $addressline = $addressline . ", " . $postcode;
 
if ($name_company) $name_company = " [" . $name_company . "]";
 
$phoneline = "";
 
if ($tel_work) $phoneline = $phoneline . "Work: " . $tel_work . "\r";
if ($tel_home) $phoneline = $phoneline . "Home: " . $tel_home . "\r";
if ($tel_mobile) $phoneline = $phoneline . "Mobile: " . $tel_mobile . "\r";
 
$emailline = "\r";
 
if ($email) $emailline = "Email: " . $email . "\r";
 
echo "BEGIN:VCALENDAR\nVERSION:2.0\n";
echo "BEGIN:VEVENT\n";
echo "DTSTART:";
printf("%04d",$year);
printf("%02d",$month);
printf("%02d",$day);
echo "T";
printf("%02d",$hours);
printf("%02d",$minutes);
echo "00\n";
echo "DTEND:";
printf("%04d",$yearend);
printf("%02d",$monthend);
printf("%02d",$dayend);
echo "T";
printf("%02d",$hoursend);
printf("%02d",$minutesend);
echo "00\n";
 
//replace newlines with carriage returns so ical picks them up ok
$desc = str_ireplace ( "\n", "", $work_expected);
 
echo "SUMMARY:Job $job_number [$job_type_desc] - $name_first $name_last $name_company\n";
echo "LOCATION:$addressline\n";
echo "DESCRIPTION:$desc\r\r$phoneline$emailline\n";
echo "END:VEVENT\n";
echo "END:VCALENDAR";
 
?>
Forum: 
Alon Swartz's picture

You need to set the content disposition to attachment to force the browser to download/save the file instead of displaying it.

You could either do this in your php code (I assume, as I've done this in a Django application), or you could configure the webserver to do it for you.

It should be something like this:

/var/www/.htaccess

<FilesMatch "\.(?i:ics|vcf)$">
  Header set Content-Disposition attachment
</FilesMatch>

You might need to reload the apache service, I don't recall...

If you look at my PHP code I pasted you'll see I already do that, otherwise it wouldn't work on anything else.  I don't have any .htaccess files set on any other server, and don't set anything special on the default Ubuntu LAMP.

This only happens on the TurnKey LAMP setup, so it's something that the rest of the world has as a default, but the TurnKey one doesn't.

My code hasn't changed, just the server to to Turnkey LAMP and it no longer works in any of the dozens of PHP routines that do the same thing.  They all work on every other server, none work on this.

Alon Swartz's picture

Sorry, my bad... I skipped over your code snippet as I replied via email and it didn't render very well in my mail client.

I'll try duplicate the issue in a VM and reply back when I have more info...

Add new comment