benphp Posted August 16, 2008 Share Posted August 16, 2008 Let's say I have a txt, htm, swf, etc. file that I want to offer as a download but I don't want the browser to open it - I want to launch a download. Can the be done via PHP or is that a JS thing? Link to comment https://forums.phpfreaks.com/topic/119924-solved-how-to-force-a-download-is-that-php/ Share on other sites More sharing options...
johnsmith153 Posted August 16, 2008 Share Posted August 16, 2008 <?php //downloads the file $file = 'file.jpg'; $fileurl = 'images/'.$file; if(!file) {die('file not found');} else { header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Transfer-Encoding: binary"); readfile($fileurl); } exit; ?> Link to comment https://forums.phpfreaks.com/topic/119924-solved-how-to-force-a-download-is-that-php/#findComment-617785 Share on other sites More sharing options...
benphp Posted August 16, 2008 Author Share Posted August 16, 2008 Shweet. Thanks! Link to comment https://forums.phpfreaks.com/topic/119924-solved-how-to-force-a-download-is-that-php/#findComment-617787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.