下载文件的PHP脚本正在下载自身而不是文件
我使用这个链接是为了开发一个简单的脚本来下载一个Android.apk文件。但不是下载文件,而是下载自己 这是我的密码:下载文件的PHP脚本正在下载自身而不是文件,php,apache,Php,Apache,我使用这个链接是为了开发一个简单的脚本来下载一个Android.apk文件。但不是下载文件,而是下载自己 这是我的密码: <?php $filename = shell_exec('ls /var/www/html/app/*.apk'); $contenttype = "application/force-download"; header("Content-Type: " . $contenttype); header("Content-Disposition: attachmen
<?php
$filename = shell_exec('ls /var/www/html/app/*.apk');
$contenttype = "application/force-download";
header("Content-Type: " . $contenttype);
header("Content-Disposition: attachment; filename=\"" . basename($filename) . "\";");
readfile($filename);
exit();
?>
Php.info由Apache正确呈现
谢谢。您的路径设置不正确 尝试使用真实的路径/文件名:
$filename = "/var/www/html/app/nameofyourfile.apk";
而且您的内容类型设置不正确,请尝试:
Content-type: application/com.android.package-install
如果这两个错误得到纠正,它可能会强制下载您的apk文件
不管怎样,这应该有效->
<?php
$filename = "/var/www/html/app/yourfile.apk";
$contenttype = "application/com.android.package-install";
header("Content-Type: " . $contenttype);
header("Content-Disposition: attachment; filename=$filename);
readfile($filename);
?>
如果您从stack上的问题中阅读示例下面的注释,您会看到已经在说mime类型不正确。APK的internet媒体类型是application/com.android.package-install always
,或者通用的应用程序/八位字节流
<代码>应用程序/apk
不标准或不常见。请编辑答案。