Skip to content

Instantly share code, notes, and snippets.

@mooror
Created October 18, 2018 20:18
Show Gist options
  • Save mooror/075340695b386525072ab0dc6c5275ab to your computer and use it in GitHub Desktop.
Save mooror/075340695b386525072ab0dc6c5275ab to your computer and use it in GitHub Desktop.
<?php
...
$download = $request->getVar("download") ? true : false;
if ($download) {
// Get the the product file path,name,type, and size
$productFile = $product->FullUpload()->getAbsoluteURL();
$productFileName = $product->FullUpload()->getFilename();
$productFileType = $product->FullUpload()->getMimeType();
$productFileSize = $product->FullUpload()->getAbsoluteSize();
// Update the HTTPResponse object with the proper download headers
$this->returnDownloadResponse();
$this->setResponse(new HTTPResponse());
$response = $this->getResponse();
$response->setStatusCode(200);
$response->setBody(readfile($productFile));
$response->addHeader("Content-Disposition", 'attachment;filename="'.$productFileName.'"');
$response->addHeader("Content-Type", $productFileType);
$response->addHeader("Content-Length", $productFileSize);
// Return the HTTPResponse object
return $response;
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment