我创建了一个函数,一旦用户单击某个链接,就会发出一个下载,该文件位于第三方存储服务(Sugar )中,并通过他们的REST访问。现在我已经创建了强制下载功能,并测试了它在localhost上运行良好(会提示下载对话框),但是当我在服务器上运行该函数时,它会返回一个错误页面“Found”。我想这可能是一些需要在服务器端设置的PHP配置,但我不知道是哪一种,所以非常感谢您的任何帮助或提示。
下面是代码的一个片段:
$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();发布于 2014-02-15 09:33:07
事实证明,经过进一步的故障排除后,这个问题与输出缓冲有关,所以我只需要在服务器配置上启用它。
发布于 2014-02-15 09:39:18
尝试在打印函数之前添加ob_get_clean();,如下所示:
ob_get_clean();
//file is returned as binary data from the API
print($sugarsync->download(urldecode($url)));
exit();https://stackoverflow.com/questions/21795079
复制相似问题