How to set header to download file .apk or .jar?
Asked 07 September, 2021
Viewed 360 times
  • 59
Votes

I have a sample $file is test.zip or test.apk or test.jar

$len = filesize($file);
$filename = basename($file);
ob_end_clean();
JResponse::clearHeaders();
JResponse::setHeader('Pragma', 'public', true);
JResponse::setHeader('Expires', '0', true);
JResponse::setHeader('Cache-Control', 'must-revalidate, post-check=0, pre-check=0', true);
JResponse::setHeader('Content-Type', $file, true);
JResponse::setHeader('Content-Disposition', 'attachment; filename='.$filename.';', true);
JResponse::setHeader('Content-Transfer-Encoding', 'binary', true);
JResponse::setHeader('Content-Length', $len, true);
JResponse::sendHeaders();
echo JFile::read($file);

When read file as test.zip is result OK, But when read file test.apk or test.jar is system error, How to set header to read this file (apk, jar)

2 Answer