Example #1
0
 /**
  * for attachement downloads
  * 
  */
 function getfile()
 {
     $id = JRequest::getInt('file');
     $user =& JFactory::getUser();
     $path = REAttach::getAttachmentPath($id, max($user->getAuthorisedViewLevels()));
     $mime = redEVENTHelper::getMimeType($path);
     $doc =& JFactory::getDocument();
     $doc->setMimeEncoding($mime);
     header('Content-Disposition: attachment; filename="' . basename($path) . '"');
     if ($fd = fopen($path, "r")) {
         $fsize = filesize($path);
         header("Content-length: {$fsize}");
         header("Cache-control: private");
         //use this to open files directly
         while (!feof($fd)) {
             $buffer = fread($fd, 2048);
             echo $buffer;
         }
     }
     fclose($fd);
     return;
 }