我需要下载一个apk应用程序,但我需要将用户保留在我的页面中或将他重定向到另一个页面带标题我只能下载应用程序或将他重定向到另一个页面,但我不能同时执行这两个页面我的PHP代码 :
$b= "location";
echo "<script>window.location.href = '$b';</script>" ;
$file = 'apk.apk';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
}
@aron9forever感谢您的帮助,我找到了一个很好的方法:
$e= "url.com" ;
echo "<script>setTimeout(function(){window.location.href = '$e';} ,2)</script>" ;
echo "<iframe src='download.php' ></iframe>" ;
和下载.php :
<?php
$file = 'apk1.apk';
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
}
?>
根据我的研究5分钟。 你所要求的是不可能的。
以一个页面为例,该页面下载了某些内容,然后重定向到"感谢您下载"
他们实际这样做的方式是将您带到"谢谢"页面,然后开始下载。
若要在代码中实现这一点,需要先打开$b
位置,然后在该脚本中通过重定向到包含下载的 PHP 脚本来开始下载。
例:
下载.php
$file = 'apk.apk';
if (file_exists($file))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
}
你好.php
$b= "download.php";
echo "Hello! <script>window.location.href = '$b';</script>" ;
当您访问hello时.php您将看到Hello!并开始下载