【发布时间】:2012-02-28 13:43:50
【问题描述】:
我是 Zend Framework 的新手,我遇到了这样的问题。在我的网页上,我有可供用户下载的产品演示。当他们想要下载它们时,他们必须填写表格(姓名、公司、电子邮件、联系电话),然后单击提交开始下载。我希望他们被重定向到产品页面。这是我在控制器中的 showFormAction 代码:
if ($this->_request->isPost())
{
if (!$form->isValid($this->_request->getPost()))
{
//shows messages and the form again
}
else
{
$file = $this->findYoungestFile('/demo/'.$product.'/');
$this->sendFileToClient($file);
$this->_redirect('/products/'.$product);
//sending mail
$infoMail = new InfoMail($this->_request->getPost(), 'download', $product);
$this->sendInfoMails($infoMail);
}
}
else
//show form
这里是 sendFileToClient 函数
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
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));
readfile($file);
重定向不起作用。我想发送到浏览器的标头有问题,但我不知道如何解决。有人可以帮帮我吗?
感谢和问候, 马尔戈萨塔
【问题讨论】:
-
“不起作用”是什么意思?你得到什么输出?
-
它将文件发送到浏览器,发送电子邮件,但不重定向,停留在同一页面上。
-
哦。重定向也是一个标题。发送文件下载头后无效:)。
-
好的,有没有可能解决这个问题?我想知道在空白标签中进行下载操作,但我不知道该怎么做
-
我知道没有简单的方法,但您可以尝试使用 iframe(可能带有 display:none)并在其中加载文件下载标题。这很 hacky,但可能值得一试:)。
标签: zend-framework header controller action download