Ejemplo n.º 1
0
 /**
  * download the file
  *
  * @param   STRING  $file             - file path eg /var/www/j30/media/com_quick2cart/qtc_pack.zip
  * @param   STRING  $filename_direct  - for direct download it will be file path like http://
  * localhost/j30/media/com_quick2cart/qtc_pack.zip  -- for FUTURE SCOPE
  * @param   STRING  $extern           - for direct download it will be file path like http://
  * @param   STRING  $exitHere         - for direct download it will be file path like http://
  *
  * @return  html
  */
 public function download($file, $filename_direct = '', $extern = '', $exitHere = 1)
 {
     $productHelper = new productHelper();
     global $jlistConfig, $mainframe;
     $app = JFactory::getApplication();
     $view_types = array();
     //  ALLOWED  FILE EXTENTION
     $view_types = explode(',', $jlistConfig['file.types.view']);
     clearstatcache();
     //  Existiert file - wenn nicht error
     if (!$extern) {
         if (!file_exists($file)) {
             return 2;
         } else {
             $len = filesize($file);
         }
     } else {
         $len = urlfilesize($file);
     }
     // If url go to other website - open it in a new browser window
     /*   if ($extern_site){
     		echo "<script>document.location.href='$file';</script>\n";
     		exit;
     		}*/
     // If set the option for direct link to the file
     // If (0 || !$jlistConfig['use.php.script.for.download']){
     if (0) {
         if (empty($filename_direct)) {
             $app->redirect($file);
         } else {
             $app->redirect($filename_direct);
         }
     } else {
         $filename = basename($file);
         $file_extension = strtolower(substr(strrchr($filename, "."), 1));
         $ctype = $productHelper->datei_mime($file_extension);
         ob_end_clean();
         //  Needed for MS IE - otherwise content disposition is not used?
         if (ini_get('zlib.output_compression')) {
             ini_set('zlib.output_compression', 'Off');
         }
         header("Cache-Control: public, must-revalidate");
         header('Cache-Control: pre-check=0, post-check=0, max-age=0');
         header("Expires: 0");
         header("Content-Description: File Transfer");
         header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");
         header("Content-Type: " . $ctype);
         header("Content-Length: " . (string) $len);
         //  If valid extention
         //  If (!in_array($file_extension, $view_types)){
         header('Content-Disposition: attachment; filename="' . $filename . '"');
         /* } else {
         			 view file in browser
         			header('Content-Disposition: inline; filename="'.$filename.'"');
         			}*/
         header("Content-Transfer-Encoding: binary\n");
         //  redirect to category when it is set the time
         /* if (intval($jlistConfig['redirect.after.download']) > 0){
         			header( "refresh:".$jlistConfig['redirect.after.download']."; url=".$redirect_to );
         			}*/
         //  set_time_limit doesn't work in safe mode
         if (!ini_get('safe_mode')) {
             @set_time_limit(0);
         }
         @readfile($file);
     }
     if ($exitHere == 1) {
         exit;
     }
 }