Last active
January 4, 2016 15:24
-
-
Save Kcko/7e54bad6aa703f1a71f6 to your computer and use it in GitHub Desktop.
Nette download
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function downloadFile($source, $fileName){ | |
$httpResponse = $this->context->getService('httpResponse'); | |
$httpResponse->setHeader('Pragma', "public"); | |
$httpResponse->setHeader('Expires', 0); | |
$httpResponse->setHeader('Cache-Control', "must-revalidate, post-check=0, pre-check=0"); | |
$httpResponse->setHeader('Content-Transfer-Encoding', "binary"); | |
$httpResponse->setHeader('Content-Description', "File Transfer"); | |
$httpResponse->setHeader('Content-Length', filesize($source)); | |
$this->sendResponse(new FileResponse($source, $fileName)); | |
} | |
public function handleQrCodeDownload($hash, $id) | |
{ | |
$user = $this->model->find($id); | |
if ($hash !== sha1($user->id . $user->slug)) | |
{ | |
$this->error(); | |
} | |
// lepsi cesta k souboru? http://forum.nette.org/cs/21269-fileresponse-soubor-neexistuje#p145741 | |
$userWebalize = Nette\Utils\Strings::webalize($user->firstname . '-' . $user->lastname); | |
$response = new Nette\Application\Responses\FileResponse(WWW_DIR.'/storage/images/200x200/'.$hash.'.png', 'qr-'.$userWebalize.'.png'); | |
$this->sendResponse($response); | |
} | |
// https://forum.nette.org/cs/21269-fileresponse-soubor-neexistuje#p145741 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment