首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PHP强制下载问题(服务器配置问题)

PHP强制下载问题(服务器配置问题)
EN

Stack Overflow用户
提问于 2014-02-15 08:15:15
回答 2查看 146关注 0票数 0

我创建了一个函数,一旦用户单击某个链接,就会发出一个下载,该文件位于第三方存储服务(Sugar )中,并通过他们的REST访问。现在我已经创建了强制下载功能,并测试了它在localhost上运行良好(会提示下载对话框),但是当我在服务器上运行该函数时,它会返回一个错误页面“Found”。我想这可能是一些需要在服务器端设置的PHP配置,但我不知道是哪一种,所以非常感谢您的任何帮助或提示。

下面是代码的一个片段:

代码语言:javascript
复制
$sugarsync = new SugarSync($refreshtoken);

$response = $sugarsync->get($url); 
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: no-cache, must-revalidate");
header("Content-Type: ".$response->mediaType);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".$response->displayName.";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".$response->size);

//file is returned as binary data from the API
print($sugarsync->download(urldecode($url)));
exit();
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-02-15 09:33:07

事实证明,经过进一步的故障排除后,这个问题与输出缓冲有关,所以我只需要在服务器配置上启用它。

票数 0
EN

Stack Overflow用户

发布于 2014-02-15 09:39:18

尝试在打印函数之前添加ob_get_clean();,如下所示:

代码语言:javascript
复制
ob_get_clean();
//file is returned as binary data from the API
print($sugarsync->download(urldecode($url)));
exit();
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21795079

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档