pebriana

Controller Download

May 30th, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. public function actionDownloadFiles($id)
  2.         {
  3.                 $material = Inbox::model()->findByPk($id);
  4.                 $src = "folder/to/".$material->location_file;
  5.                 if(@file_exists($src)) {
  6.                         $path_parts = @pathinfo($src);
  7.                         //$mime = $this->__get_mime($path_parts['extension']);
  8.                         header('Content-Description: File Transfer');
  9.                         header('Content-Type: application/octet-stream');
  10.                         //header('Content-Type: '.$mime);
  11.                         header('Content-Disposition: attachment; filename='.basename($src));
  12.                         header('Content-Transfer-Encoding: binary');
  13.                         header('Expires: 0');
  14.                         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  15.                         header('Pragma: public');
  16.                         header('Content-Length: ' . filesize($src));
  17.                         ob_clean();
  18.                         flush();
  19.                         readfile($src);
  20.                 } else {
  21.                         header("HTTP/1.0 404 Not Found");
  22.                         exit();
  23.                 }
  24.  
  25.         }
Add Comment
Please, Sign In to add comment