0

Hello
I've got some swf files linked to my website, and currently, when clicking on the link, it opens the content in a new window, however I want to make the file downloadable when the link is clicked, how to do this?

2
Contributors
3
Replies
4
Views
6 Years
Discussion Span
Last Post by Ritesh_4
1

You could instruct your users to "right click and select save on disk" or something like that. If that's not what you want, there are some headers you can use for this. Copied from http://elouai.com/force-download.php:

header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers 
header("Content-Type: application/force-download"); // or application/x-shockwave-flash, I don't know which works better
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename=\"".basename($filename)."\";" ); // filename should come here
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename)); // ... and the size.

To make it easier, you could just create a php page that does this (instead of converting this to .htaccess or something like that stuff), but that's kinda up to you.

0

managed to make it work using

<?php
$file = $_GET['file'];
header ("Content-type: octet/stream");
header ("Content-disposition: attachment; filename=".$file.";");
header("Content-Length: ".filesize($file));
readfile($file);
exit;
?>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.