Question

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();
Was it helpful?

Solution

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.

OTHER TIPS

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();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top