【发布时间】:2019-05-27 08:52:07
【问题描述】:
我想提供一个.APK 文件供用户下载。我有一个CDN,它工作正常。当我请求文件下载时,它从CDN 下载。但我有一个问题。我的用户请求从 Android 设备下载,在这种情况下,下载纯 APK 文件会遇到麻烦,因为我希望用户安装该 APK 文件,而使用纯 APK 是不可能的,因为我知道。所以我像这样创建一个.php 文件并添加'Content-Type: application/vnd.android.package-archive':
<?php
$file = 'myfile.apk'; //File that we want to send to user.
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/vnd.android.package-archive');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>
当我请求download.php时,它的工作和用户可以下载并安装APK文件。现在我的问题是,在这种情况下,该文件是从 CDN 下载的吗?我想要从 CDN 提供 download.php 和 APK 文件,因为我没有足够的流量。
或者这可以添加'Content-Type: application/vnd.android.package-archive' 到从CDN 下载文件而不需要php?
PS:当我请求纯APK文件时,因为它来自CDN,它像缓存一样立即下载,但是使用download.php,下载需要时间。这意味着在这种情况下它不是来自 CDN?
【问题讨论】:
标签: php android download http-headers cdn