<?
########## Confixx(R) 3.0 Professional ############
####### Copyright SWsoft, Inc. 2004-2005 ##########
#### http://www.sw-soft.com - info@sw-soft.com ####

ob_start();
$DEBUG=0;

$GLOBALS["noflash"]=TRUE;

include_once("auth.php");

include("ftp_config.php");
include("ftp_class.php");
include("ftp_functions.php");

$ftp = new ftp();

$ftp->debug = FALSE;


if (!$ftp->ftp_connect($ftp_host)) {
   die("Cannot connect\n");
}
if (!$ftp->ftp_login($ftp_user, $ftp_pass)) {
   $ftp->ftp_quit();
   die("Login failed\n");
}

if($download) {  
  $pathfilename = explode("/",$download);
  $filename = $pathfilename[((count($pathfilename)-1))];
  $path = dirname($download);
  if($ftp->ftp_chdir($path)) {

    if(!$filesize || $maxDownloadSize<=0 || $filesize <= $maxDownloadSize) {

      $extension = strrchr($filename,".");

      $mimeTextTypes = explode(" ",$mimeTextTypes);
      for($i=0;$i<count($mimeTextTypes);$i++) {
	$mimeTextType = ".".$mimeTextTypes[$i];

	if($mimeTextType == $extension) {
	  $mimeType = "text/plain";
	}
      }
      if($extension == ".jpg" || $extension == ".jpeg") {
	$mimeType = "image/jpeg";
      }
      if($extension == ".gif") {
	$mimeType = "image/gif";
      }
      if($extension == ".png") {
	$mimeType = "image/png";
      }
      if($extension == ".mp3") {
	$mimeType = "audio/x-mp3";
      }
      if($extension == ".ogg") {
	$mimeType = "audio/x-ogg";
      }
      if($extension == ".zip") {
	$mimeType = "application/zip";
      }
      if($extension == ".gz" || $extension == ".tgz") {
	$mimeType = "application/x-gzip";
      }
      if($extension == ".bz2" ) {
	$mimeType = "application/x-bzip2";
      }

      if(!$mimeType) {
	$mimeType = "application/octet-stream";
      }

      if ($DEBUG){
	echo "mimeType = $mimeType<br>\n";
      }
      
      ob_end_clean();
      
	  header("Pragma: cache");
      header("Content-Type: $mimeType; name=\"$filename\"");
      //	header("Content-Disposition: inline; filename=\"$filename\"");
      header("Content-Disposition: attachment; filename=\"$filename\"");


      header("Content-Description: $filename");
      if ($filesize){
	header("Accept-Ranges: bytes");
	header("Content-Length: $filesize");
      }
     
      if ($ftp->ftp_getstart($filename,1)){
	while (!$ftp->ftp_geteof()){
	  $chunk = $ftp->ftp_getnext(); 
	  if ($chunk){
	    
	    echo $chunk;
	    
	  }
	}	
	$ftp->ftp_getstop();
      }
    } else {
      addInfoBoxMsg($lang_text['wftp_download_filesize'],"|%maxfilesize%","|$maxDownloadSize");
      showInfoBox();
    }
  }
}

$ftp->ftp_quit();
exit;
?>
