Example #1
0
 public function download()
 {
     tzportfolioplusimport('phpclass.connection_tools_class');
     $model = $this->getModel('Article', 'TZ_Portfolio_PlusModel')->download();
     $file = JPATH_ROOT . DIRECTORY_SEPARATOR . 'media' . DIRECTORY_SEPARATOR . $model;
     $mainframe = JFactory::getApplication();
     if (JFile::exists($file)) {
         tzConnector::sendfile($file, $this->check_filetype($file));
         $mainframe->close();
     }
     return true;
 }
Example #2
0
 public function download()
 {
     require_once JPATH_COMPONENT_ADMINISTRATOR . '/' . 'libraries' . '/' . 'connectionTools.class.php';
     $model = $this->getModel('P_Article', 'TZ_PortfolioModel')->download();
     $file = JPATH_ROOT . '/' . 'media' . '/' . $model;
     $mainframe = JFactory::getApplication();
     if (JFile::exists($file)) {
         tzConnector::sendfile($file, $this->check_filetype($file));
         $mainframe->close();
     }
     return true;
 }
 /**
  * Set headers and send the file to the client
  *
  * @author Andreas Gohr <*****@*****.**>
  * @param string The full path to the file
  * @param string The Mime Type of the file
  */
 function sendFile($file, $mime, $overrideFileName = '')
 {
     // send headers
     header("Content-Type: {$mime}");
     list($start, $len) = tzConnector::http_rangeRequest(filesize($file));
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Accept-Ranges: bytes');
     //application mime type is downloadable
     if (strtolower(substr($mime, 0, 11)) == 'application') {
         if ($overrideFileName == '') {
             $filename = basename($file);
         } else {
             $filename = $overrideFileName;
         }
         header('Content-Disposition: attachment; filename="' . $filename . '";');
     }
     $chunksize = 1 * (1024 * 1024);
     // send file contents
     $fp = @fopen($file, "rb");
     if ($fp) {
         fseek($fp, $start);
         //seek to start of range
         $chunk = $len > $chunksize ? $chunksize : $len;
         while (!feof($fp) && $chunk > 0) {
             @set_time_limit(0);
             // large files can take a lot of time
             print fread($fp, $chunk);
             flush();
             $len -= $chunk;
             $chunk = $len > $chunksize ? $chunksize : $len;
         }
         fclose($fp);
     } else {
         header("HTTP/1.0 500 Internal Server Error");
         print "Could not read {$file} - bad permissions?";
         die;
     }
 }