|
Posted by Chris on 08/10/05 22:49
A comment is inline.
Sebastian wrote:
> some of my users are complaining that when they try download media
> files (mp3, mpeg, etc) their media player opens and doesn't allow them
> to physically download the media. These are IE users, firefox seems to
> like my code, but IE refuses to download the file and plays it instead..
>
> can anyone view my code and see how i can force media file downloads
> on IE?
>
> --snip--
>
> header('Cache-control: max-age=31536000');
> header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 31536000) . '
> GMT');
> header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $file['date']) . '
> GMT');
>
> if ($extension != 'txt')
> {
> header("Content-disposition: inline; filename=\"$file[type]\"");
> }
> else
> {
> // force txt files to prevent XSS
> header("Content-disposition: attachment; filename=\"$file[type]\"");
> }
>
if you just remove this extension check, and set everything as an
attachment, that is the normal way to do things. The major browsers will
pop up a Save As... dialog
> header('Content-Length: ' . $file['size']);
>
> switch($extension)
> {
> case 'zip':
> $headertype = 'application/zip';
> break;
> case 'exe':
> $headertype = 'application/octet-stream';
> break;
>
> case 'mp3':
> $headertype = 'audio/mpeg';
> break;
>
> case 'wav':
> $headertype = 'audio/wav';
> break;
> case 'mpg':
> $headertype = 'video/mpeg';
> break;
>
> case 'avi':
> $headertype = 'video/avi';
> break;
>
> default:
> $headertype = 'unknown/unknown';
> }
>
> header('Content-type: ' . $headertype);
>
> --/snip--
>
>
Navigation:
[Reply to this message]
|