【问题标题】:PHP force download issue (server config issue)PHP 强制下载问题(服务器配置问题)
【发布时间】:2014-02-15 08:15:15
【问题描述】:

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

这是代码的sn-p:

$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();

【问题讨论】:

标签: php force-download


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    尝试在您的打印功能之前添加ob_get_clean();,如下所示:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-19
      • 2014-12-03
      • 1970-01-01
      • 1970-01-01
      • 2016-09-12
      • 2011-02-21
      • 1970-01-01
      相关资源
      最近更新 更多