16

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)

Hai Truong
  • 200
  • 1
  • 1
  • 8

2 Answers2

47

setHeader in Content-Type is

'apk' => 'application/vnd.android.package-archive'
'jar' => 'application/java-archive'

More: https://svn.apache.org/repos/asf/httpd/httpd/trunk/docs/conf/mime.types

-1

Try using

Content-type: application/jar
Content-type: application/apk

But i think this line of code is wrong.

JResponse::setHeader('Content-Type', $file, true);

Probabily you must use like this

JResponse::setHeader('Content-Type', 'application/jar', true);
João Mosmann
  • 2,884
  • 19
  • 25
  • 5
    Please use `application/vnd.android.package-archive`. `Content-type: application/apk` is not the correct Content-type for apk, it will cause Chrome to show the "Can't open file" error (Android Download Manager (default) open file depend on correct Content-type) – vk.edward.li Apr 14 '16 at 07:50