You are here: Re: [PHP] force download « PHP « IT news, forums, messages
Re: [PHP] force download

Posted by "James R." on 08/10/05 21:40

That would be browser dependent, something you have no control over. Maybe
you can include a little text message saying "right-click save as" for the
users not intelligent enough to figure it out themselves.


----- Original Message -----
From: "Sebastian" <sebastian@broadbandgaming.net>
To: <php-general@lists.php.net>
Sent: Wednesday, August 10, 2005 12:00 PM
Subject: [PHP] force download


> 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]\"");
> }
>
> 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--
>
>
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.338 / Virus Database: 267.10.5/67 - Release Date: 8/9/2005
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация