Force to download a file - Joomla! Forum - community, help and support
hi,
i'm developing component torrents catalog joomla 1.5. i'm new @ developing coponents joomla.
my problem is, i'd send file user, hide real path file.
i thought php header function solution:
i put code in 1 of component controller method, dosen't work, cause headers sent before joomla call task method. sory english, hope u know mean.
any ideas?
i'm developing component torrents catalog joomla 1.5. i'm new @ developing coponents joomla.
my problem is, i'd send file user, hide real path file.
i thought php header function solution:
code: select all
<?php
header('content-type: application/pdf');
header('content-disposition: attachment; filename="downloaded.pdf"');
readfile('original.pdf');
?>
i put code in 1 of component controller method, dosen't work, cause headers sent before joomla call task method. sory english, hope u know mean.
any ideas?
i found following somewhere in google , works me:
code: select all
function force_download($filename, $name ) {
$filesize = filesize($filename);
if($filesize) {
ini_set('zlib.output_compression', 'off');
/* ie fix : firefox compatible */
header("content-type: application/application/octet-stream\n");
header("content-disposition: attachment; filename=\"$name\"");
/* read */
$contents = fread(fopen($filename, "rb"), filesize($filename));
/* print */
echo $contents;
exit;
} else {
return 0;
}
}
Comments
Post a Comment