快速问题:我有一个强制用户输入电子邮件的表单,之后下载/附件被按下并且文件被下载...文件下载正常...但是...PHP下载方法挂断页面...推送下载的最佳实践?
我的问题是,当下载开始时,页面锁定,用户无法导航任何地方或在页面上做任何事情,直到文件被下载(即:点击下面的“回家”链接)。比我在这里提出的更好的解决方案?我知道我可能错过了一些非常简单的事情......这是我第一次创建私人下载页面。
<script type="text/javascript">
function redirect_function(loc){
window.location = loc;
}
</script>
<?php
// after form is submitted
$condition_met=check($_POST['email']);
if($condition_met) { ?>
<p>Your file will begin downloading in 5 seconds.</p> <a>go home</a>
<script type="text/javascript">
setTimeout('redirect_function("download.php")', 5000);
</script>
<?php } ?>
被叫(的download.php)页面看起来是这样的,这是它挂上网页...
<?php
ob_start();
if($some_condition) { // check for authorization, etc
$file='location/file.ext';
header('Content-type: application/force-download');
header('Content-disposition: attachment; filename="'. basename($file) .'"');
header('Content-length: '. filesize($file));
readfile($file);
} else {
echo "error message";
}
ob_end_flush();
?>
5000的超时时间是什么? – Stewie 2010-09-28 20:04:03
超时在调用下载页面之前等待5秒...更多的形式,可能不是必需的。 – Jon 2010-09-28 20:06:21
这个文件有多大? – JAL 2010-09-28 23:06:51