[英]PHP force download issue (server config issue)
我创建了一个函数,可以在用户单击链接后发布下载,该文件位于第三方存储服务(Sugar Sync)中,可通过其REST API访问。 现在,我已经创建了强制下载功能并测试了它在localhost上的运行状况(提示下载对话框),但是当我在服务器上运行该功能时,它会返回错误页面“找不到文件”。 我认为这可能是一些需要在服务器端进行设置的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();
事实证明,在进行进一步的故障排除之后,问题与输出缓冲有关 ,因此我只需要在服务器配置上启用它即可。
尝试添加ob_get_clean();
在您的打印功能像这样之前:
ob_get_clean();
//file is returned as binary data from the API
print($sugarsync->download(urldecode($url)));
exit();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.