Pra*_*sad 1 php attachment download http-headers symfony-1.4
我正在尝试通过操作传递CSV文件.响应中的mime类型仍显示为text/html.有人可以帮忙吗?谢谢
//$this->setLayout(false);
//$this->getUser()->shutdown();
//sfConfig::set('sf_web_debug', false);
$response = $this->getContext()->getResponse();
$response = $this->getResponse();
$response->clearHttpHeaders();
$response->setHttpheader('Pragma: public', true);
$response->addCacheControlHttpHeader('Cache-Control', 'must-revalidate');
$response->setContentType('application/octet-stream', true);
$response->setHttpHeader('Content-Description', 'File Transfer');
$response->setHttpHeader('Content-Transfer-Encoding', 'binary', true);
$response->setHttpHeader('Content-Length', filesize($file_path));
$response->setHttpHeader('Content-Disposition', 'attachment; filename="' . $file_name . '"');
$this->getResponse()->sendHttpHeaders();
//$response->setContent(file_get_contents($file_path));
//readfile($file_path);
$this->renderText(file_get_contents($file_path));
//return sfView::NONE;
return sfView::HEADER_ONLY;
Run Code Online (Sandbox Code Playgroud)
相信我,在到达这里之前,我的搜索结果都是紫色的.正如你可以看到上面的所有排列和组合,我仍然无法实现这一点!
尝试这样的事情:
$path = 'absolute/path/to/the/file';
/** @var $response sfWebResponse */
$response = $this->getResponse();
$response->setContentType('text/csv');
$response->setHttpHeader('Content-Disposition', 'attachment; filename="' . basename($path) . '"');
$response->setContent(file_get_contents($path));
return sfView::NONE;
Run Code Online (Sandbox Code Playgroud)
注意: filename必须是ASCII,参见RFC 6266
| 归档时间: |
|
| 查看次数: |
7203 次 |
| 最近记录: |