download.php
Upload User: feiyaoda
Upload Date: 2016-11-21
Package Size: 9556k
Code Size: 10k
Category:

WEB Mail

Development Platform:

PHP

  1. <?php
  2. /*
  3.     package::i.tools
  4.     
  5.     php-downloader  v1.0    -   www.ipunkt.biz
  6.     
  7.     (c) 2002 - www.ipunkt.biz (rok)
  8. */
  9. //  INFO    //
  10. $info  = 'php-downloader v1.0 - www.ipunkt.biz'."n";
  11. $info .= '===================================='."n";
  12. $info .= $_SERVER['HTTP_REFERER']."n";
  13. //  USER-INFO   //
  14. // Whether the os php is running on is windows or not
  15. if (!defined('IS_WINDOWS')) {
  16.     if (defined('PHP_OS') && eregi('win', PHP_OS)) {
  17.         define('IS_WINDOWS', 1);
  18.     } else {
  19.         define('IS_WINDOWS', 0);
  20.     }
  21. }
  22. // Determines platform (OS), browser and version of the user
  23. // Based on a phpBuilder article:
  24. //   see http://www.phpbuilder.net/columns/tim20000821.php
  25. if (!defined('USR_OS')) {
  26.     // loic1 - 2001/25/11: use the new globals arrays defined with php 4.1+
  27.     if ( !empty($_SERVER['HTTP_USER_AGENT']) )
  28.     {
  29.         $HTTP_USER_AGENT = $_SERVER['HTTP_USER_AGENT'];
  30.     }
  31.     elseif ( !empty($HTTP_SERVER_VARS['HTTP_USER_AGENT']) )
  32.     {
  33.         $HTTP_USER_AGENT = $HTTP_SERVER_VARS['HTTP_USER_AGENT'];
  34.     }
  35.     elseif ( !isset($HTTP_USER_AGENT) )
  36.     {
  37.         $HTTP_USER_AGENT = '';
  38.     }
  39.     // 1. Platform
  40.     if ( strstr($HTTP_USER_AGENT, 'Win') )
  41.     {
  42.         define('USR_OS', 'Win');
  43.     }
  44.     elseif ( strstr($HTTP_USER_AGENT, 'Mac') )
  45.     {
  46.         define('USR_OS', 'Mac');
  47.     }
  48.     elseif ( strstr($HTTP_USER_AGENT, 'Linux') )
  49.     {
  50.         define('USR_OS', 'Linux');
  51.     }
  52.     elseif ( strstr($HTTP_USER_AGENT, 'Unix') )
  53.     {
  54.         define('USR_OS', 'Unix');
  55.     }
  56.     elseif ( strstr($HTTP_USER_AGENT, 'OS/2') )
  57.     {
  58.         define('USR_OS', 'OS/2');
  59.     }
  60.     else
  61.     {
  62.         define('USR_OS', 'Other');
  63.     }
  64.     // 2. browser and version
  65.     if ( ereg('Opera(/| )([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version) )
  66.     {
  67.         define('USR_BROWSER_VER', $log_version[2]);
  68.         define('USR_BROWSER_AGENT', 'OPERA');
  69.     }
  70.     elseif ( ereg('MSIE ([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version) )
  71.     {
  72.         define('USR_BROWSER_VER', $log_version[1]);
  73.         define('USR_BROWSER_AGENT', 'IE');
  74.     }
  75.     elseif ( ereg('OmniWeb/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version) )
  76.     {
  77.         define('USR_BROWSER_VER', $log_version[1]);
  78.         define('USR_BROWSER_AGENT', 'OMNIWEB');
  79.     }
  80.     elseif ( ereg('Mozilla/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version) )
  81.     {
  82.         define('USR_BROWSER_VER', $log_version[1]);
  83.         define('USR_BROWSER_AGENT', 'MOZILLA');
  84.     }
  85.     elseif ( ereg('Konqueror/([0-9].[0-9]{1,2})', $HTTP_USER_AGENT, $log_version) )
  86.     {
  87.         define('USR_BROWSER_VER', $log_version[1]);
  88.         define('USR_BROWSER_AGENT', 'KONQUEROR');
  89.     }
  90.     else
  91.     {
  92.         define('USR_BROWSER_VER', 0);
  93.         define('USR_BROWSER_AGENT', 'OTHER');
  94.     }
  95. }
  96. if ( isset($_REQUEST['file']) )
  97. {
  98.     //  defines filename, extension and also mime types
  99.     if ( file_exists($_REQUEST['file']) )
  100.     {
  101.         // this part is buggy like this
  102.         /*
  103.         $pi = pathinfo($_REQUEST['file']);
  104.         $path = $pi['dirname'].'/';
  105.         $filename = $pi['basename'];
  106.         */
  107.         
  108.         $pi = pathinfo($_REQUEST['file']);
  109.         $path = $pi['dirname'].'/';
  110.         $filename = $pi['basename'];
  111.                 
  112.         
  113.         
  114.         $info .= $filename.' ('.filesize($path.$filename).' bytes)';
  115.         
  116.         if ( $_REQUEST['method'] && $_REQUEST['method'] == 'tar' )
  117.         {
  118.             $ext = '.tar';
  119.             $mime_type = 'application/x-tar';
  120.         }        
  121.         
  122.         if ( $_REQUEST['method'] && $_REQUEST['method'] == 'gzip')
  123.         {
  124.             $ext = '.tar.gz';
  125.             $mime_type = 'application/x-gzip';
  126.         }
  127.         elseif ( $_REQUEST['method'] && $_REQUEST['method'] == 'zip')
  128.         {
  129.             $ext = '.zip';
  130.             $mime_type = 'application/x-zip';
  131.         }
  132.         else
  133.         {
  134.             $ext       = '';
  135.             // loic1: 'application/octet-stream' is the registered IANA type but
  136.             //        MSIE and Opera seems to prefer 'application/octetstream'
  137.             $mime_type = (USR_BROWSER_AGENT == 'IE' || USR_BROWSER_AGENT == 'OPERA')
  138.                 ? 'application/octetstream'
  139.                 : 'application/octet-stream';
  140.         }
  141.     
  142.         // Send headers
  143.         header('Content-Type: '.$mime_type);
  144.         // lem9 & loic1: IE need specific headers
  145.         if (USR_BROWSER_AGENT == 'IE')
  146.         {
  147.             header('Content-Disposition: inline; filename="'.$filename.$ext.'"');
  148.             header('Expires: 0');
  149.             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  150.             header('Pragma: public');
  151.         }
  152.         else
  153.         {
  154.             header('Content-Disposition: attachment; filename="'.$filename.$ext.'"');
  155.             header('Expires: 0');
  156.             header('Pragma: no-cache');
  157.         }
  158.     
  159.         // get dump_buffer
  160.         $fp = fopen($path.$filename, 'rb');
  161.         $dump_buffer = fread($fp, filesize($path.$filename));
  162.         fclose($fp);
  163.     
  164.         // displays the dump...
  165.         // 1. as a zipped file
  166.         if ( isset($_REQUEST['method']) && $_REQUEST['method'] == 'zip') {
  167.             if ( @function_exists('gzcompress') )
  168.             {
  169.                 include_once('./extensions/zip.class.php');
  170.                 $zipfile = new zipfile();
  171.                 $zipfile->addFile($dump_buffer, $filename);
  172.                 //$zipfile->addFile($info, 'info.txt');
  173.                 echo $zipfile->file();
  174.             }
  175.         }
  176.         // 2. as a TAR file
  177.         elseif ( isset($_REQUEST['method']) && $_REQUEST['method'] == 'tar' )
  178.         {
  179.             include_once('./extensions/tar.class.php');
  180.             
  181.             $tar = new tar();
  182.             $tar->addFile($path.$filename);
  183.             echo $tar->toTarOutput($filename.$ext, false);
  184.             
  185.         }
  186.         // 3. as a TAR gzipped file
  187.         elseif ( isset($_REQUEST['method']) && $_REQUEST['method'] == 'gzip' )
  188.         {
  189.             include_once('./extensions/tar.class.php');
  190.             
  191.             $tar = new tar();
  192.             $tar->addFile($path.$filename);
  193.             if ( @function_exists('gzencode') )
  194.                 $use_gzip = true;
  195.             else
  196.                 $use_gzip = false;
  197.             echo $tar->toTarOutput($use_gzip);
  198.         }        
  199.         // 3. on screen or as a text file
  200.         else {
  201.             echo $dump_buffer;
  202.         }
  203.         
  204.     }
  205.     else
  206.     {
  207.         echo "No such file or directory";
  208.     }
  209. }
  210. elseif ( isset($_REQUEST['files']) )
  211. {
  212.     // MODIFIED FROM php_downloader
  213.     // to handle multiple files
  214.     // it also accept another parameter $target_folder
  215.     //  defines filename, extension and also mime types
  216.         $pi = pathinfo($_REQUEST['file']);
  217.         $path = './'.$pi['dirname'].'/';
  218.         $filename = $pi['basename'];
  219.         
  220.         if ('' == $filename) $filename = 'archive';
  221.         
  222.         if ( $_REQUEST['method'] && $_REQUEST['method'] == 'tar' )
  223.         {
  224.             $ext = '.tar';
  225.             $mime_type = 'application/x-tar';
  226.         }        
  227.         
  228.         if ( $_REQUEST['method'] && $_REQUEST['method'] == 'gzip')
  229.         {
  230.             $ext = '.tar.gz';
  231.             $mime_type = 'application/x-gzip';
  232.         }
  233.         elseif ( $_REQUEST['method'] && $_REQUEST['method'] == 'zip')
  234.         {
  235.             $ext = '.zip';
  236.             $mime_type = 'application/x-zip';
  237.         }
  238.         else
  239.         {
  240.             $ext       = '';
  241.             // loic1: 'application/octet-stream' is the registered IANA type but
  242.             //        MSIE and Opera seems to prefer 'application/octetstream'
  243.             $mime_type = (USR_BROWSER_AGENT == 'IE' || USR_BROWSER_AGENT == 'OPERA')
  244.                 ? 'application/octetstream'
  245.                 : 'application/octet-stream';
  246.         }
  247.     
  248.         // Send headers
  249.         header('Content-Type: '.$mime_type);
  250.         // lem9 & loic1: IE need specific headers
  251.         if (USR_BROWSER_AGENT == 'IE')
  252.         {
  253.             header('Content-Disposition: inline; filename="'.$filename.$ext.'"');
  254.             header('Expires: 0');
  255.             header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  256.             header('Pragma: public');
  257.         }
  258.         else
  259.         {
  260.             header('Content-Disposition: attachment; filename="'.$filename.$ext.'"');
  261.             header('Expires: 0');
  262.             header('Pragma: no-cache');
  263.         }
  264.         
  265.         switch ($_REQUEST['method'])
  266.         {
  267.             case 'zip':
  268.             {
  269.                 if ( @function_exists('gzcompress') )
  270.                 {
  271.                     die('no gzip support on this server');
  272.                 }
  273.                 include_once('./extensions/zip.class.php');
  274.                 $zipfile = new zipfile();
  275.                 break;
  276.             }
  277.             case 'tar': //jump
  278.             case 'gzip':
  279.             {
  280.                 include_once('./extensions/tar.class.php');
  281.                 $tar = new tar();                
  282.                 break;
  283.             }
  284.         }
  285.     
  286.         foreach($_REQUEST['files'] as $id => $add_file)
  287.         {
  288.             // get dump_buffer
  289.             $fp = fopen($path.$add_file, 'rb');
  290.             $dump_buffer = fread($fp, filesize($path.$add_file));
  291.             fclose($fp);
  292.         
  293.             // adding
  294.             switch ($_REQUEST['method'])
  295.             {
  296.                 case 'zip': $zipfile->addFile($dump_buffer, $filename); break;
  297.                 case 'tar': // jump
  298.                 case 'gzip': $tar->addFile($path.$filename); break;
  299.             }            
  300.         }// end of foreach files
  301.         
  302.         // sending to output
  303.         $use_gzip = false;
  304.         switch ($_REQUEST['method'])
  305.         {
  306.             case 'zip':
  307.             {
  308.                 echo $zipfile->file();
  309.                 break;
  310.             }
  311.             case 'gzip':
  312.             {
  313.                 if ( @function_exists('gzencode') )
  314.                     $use_gzip = true;
  315.                 // JUMP                
  316.             }
  317.             case 'tar':
  318.             {
  319.                 echo $tar->toTarOutput($use_gzip);                
  320.                 break;
  321.             }
  322.         }
  323. }
  324. else
  325.     header('location: index.html');
  326. exit;
  327. ?>