Jump to content

Forcing downloads - Content-Type header necessary?


dmhouse

Recommended Posts

Hi all. I'm trying to write a script to force the download of a file. I understand the correct way to do this is by means of the Content-disposition header; indeed, I've had success in Firefox 3, IE 6 & 7 with the following:

 

<?php
header('Content-disposition: attachment; filename="test.txt"');
header('Content-type: text/plain');
header('Content-length: 2');

echo 'yo';
?>

 

However nearly every resource I see on the internet advocates the usage of some kind of spoofed Content-type header, e.g. application/octet-stream, application/download, application/x-download etc. Does anyone know whether this is necessary for certain browsers, or can I get away with just Content-disposition?

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.