Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
下载文件的PHP脚本正在下载自身而不是文件_Php_Apache - Fatal编程技术网

下载文件的PHP脚本正在下载自身而不是文件

下载文件的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

我使用这个链接是为了开发一个简单的脚本来下载一个Android.apk文件。但不是下载文件,而是下载自己

这是我的密码:

<?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
不标准或不常见。请编辑答案。