I know this can be done using PHP but because ExpressionEngine has its own way of doing things it’s not working as expected. That or I am not doing it correctly.
I just want to be able to force downloads of certain files (mp3, pdf, etc) instead of having them play in the browser.
I’m passing a link like this:
{exp:channel:entries ... }
<a href="http://.../download?file={my_file_url}">Download audio</a>
{/exp:channel:entries}And in the “download” template with PHP enabled I have:
<?php
$file = $_REQUEST["file"];
header('Content-Type: application/octet-stream');
header('Content-Length: '.filesize($file));
header('Content-Description: File Transfer');
header('Content-Disposition: attachment; filename="download.mp3"');
readfile($file);
?>When run I get a file with the entire URL path (replacing the slashes with dashes) containing only this:
Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 18158324 bytes) in public_html/dev/system/expressionengine/libraries/Functions.php(679) : eval()‘d code on line 1
Any ideas? Thanks…