Skip to content

Instantly share code, notes, and snippets.

Created September 4, 2015 08:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/3289950c6f1465f07a47 to your computer and use it in GitHub Desktop.
Save anonymous/3289950c6f1465f07a47 to your computer and use it in GitHub Desktop.
switch($this->request->param('Action')) {
case 'preview':
return $this->renderWith('DocumentsPage_preview', array(
'requestedFile' => $file
));
break;
case 'open':
$this->response->addHeader('Content-Type', $mime);
$this->response->addHeader('Content-Disposition', 'attachment; filename='.$file->Title + "." + $file->Extension);
$this->response->addHeader('Content-Disposition', 'inline; filename='.str_replace(' ', '_', $file->Title.'.'.$file->getExtension()));
$this->response->addHeader('Content-Length', $file->getSize());
$this->response->setBody(file_get_contents($file->getFullPath()));
//Debug::dump($this->response);
return $this->response;
break;
case 'download':
//$this->response->addHeader('Content-Description', 'File Transfer');
//$this->response->addHeader('Content-Type', $mime);
//$this->response->addHeader('Content-Disposition', 'attachment; filename='.$file->Title + "." + $file->Extension);
//$this->response->setBody(file_get_contents($file->getFullPath()));
header("Content-disposition: attachment; filename=" + $file->Title + '.' + $file->Extension + "'");
header('Content-type: ' + $mime);
readfile(file_get_contents($file->getFullPath()));
//return $this->response;
break;
default:
user_error('Unknow action');
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment