문제

I've created a function to issue a download once user click a link, the file is located in 3rd party storage service (Sugar Sync) and is accessed via their REST API. Now I've created the force download function and tested it runs fine on localhost (a download dialog is prompted), but when I run the function on the server it returns an error page of 'File not Found'. I figured this might be some PHP configuration that needs to be set on server side, but I've got no clue which, so any help or hint is greatly appreciated.

Here's a snippet of the code:

$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();
도움이 되었습니까?

해결책

As it turns out, after further troubleshooting, the problem is related to output buffering, so I just need to enable that on the server config.

다른 팁

Try adding ob_get_clean(); before your print function like so:

ob_get_clean();
//file is returned as binary data from the API
print($sugarsync->download(urldecode($url)));
exit();
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top