Re: force download

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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--




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux