Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force file download of unknown file type with PHP

Tags:

php

I am looking to force the download of a file from an external source using PHP headers. However, the file type could be ANYTHING. How can I force the download of all file types?

I hope you can understand my question and what I am trying to describe.

like image 413
Callum Whyte Avatar asked Apr 23 '12 21:04

Callum Whyte


1 Answers

You mean HTTP headers, and you're looking for RFC 2616, http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html "Content Disposition".

Send the following headers to force a download of ALL files and types:

header('Content-Disposition: attachment; filename="name.ext"');
header('Content-Type: application/octet-stream'); // or application/force-download

echo $the_file_content;
exit;
like image 102
freeone3000 Avatar answered Nov 07 '22 09:11

freeone3000