<?php
include "_includes/class.httpdownload.php";
//get share
$share_id = rawurldecode(stripslashes($_GET['share']));
$path = trim(rawurldecode(stripslashes($_GET['download'])),'/');
$share = afbGetShare($share_id);

if ($share && $share['perm_download']){
	$fullpath = TieString($share['dir'],'','/').$path;
	//check file..
	if (CheckFile($share['dir'],$fullpath)) {
		$file = GetFilename($fullpath);
		//get type
		$ext = GetExt($fullpath);
		
		//logit
		afbLogit('download',TieString($path,'/'),$share['id']);

		// Determine correct MIME type
		switch($ext) {
			case "asf":     $type = "video/x-ms-asf";                break;
			case "avi":     $type = "video/x-msvideo";               break;
			case "bin":     $type = "application/octet-stream";      break;
			case "bmp":     $type = "image/bmp";                     break;
			case "cgi":     $type = "magnus-internal/cgi";           break;
			case "css":     $type = "text/css";                      break;
			case "dcr":     $type = "application/x-director";        break;
			case "dxr":     $type = "application/x-director";        break;
			case "dll":     $type = "application/octet-stream";      break;
			case "doc":     $type = "application/msword";            break;
			case "exe":     $type = "application/octet-stream";      break;
			case "gif":     $type = "image/gif";                     break;
			case "gtar":    $type = "application/x-gtar";            break;
			case "gz":      $type = "application/gzip";              break;
			case "htm":     $type = "text/html";                     break;
			case "html":    $type = "text/html";                     break;
			case "iso":     $type = "application/octet-stream";      break;
			case "jar":     $type = "application/java-archive";      break;
			case "java":    $type = "text/x-java-source";            break;
			case "jnlp":    $type = "application/x-java-jnlp-file";  break;
			case "js":      $type = "application/x-javascript";      break;
			case "jpg":     $type = "image/jpg";                     break;
			case "jpe":     $type = "image/jpg";                     break;
			case "jpeg":    $type = "image/jpg";                     break;
			case "lzh":     $type = "application/octet-stream";      break;
			case "mdb":     $type = "application/mdb";               break;
			case "mid":     $type = "audio/x-midi";                  break;
			case "midi":    $type = "audio/x-midi";                  break;
			case "mov":     $type = "video/quicktime";               break;
			case "mp2":     $type = "audio/x-mpeg";                  break;
			case "mp3":     $type = "audio/mpeg";                    break;
			case "mpg":     $type = "video/mpeg";                    break;
			case "mpe":     $type = "video/mpeg";                    break;
			case "mpeg":    $type = "video/mpeg";                    break;
			case "pdf":     $type = "application/pdf";               break;
			case "php":     $type = "application/x-httpd-php";       break;
			case "php3":    $type = "application/x-httpd-php3";      break;
			case "php4":    $type = "application/x-httpd-php";       break;
			case "png":     $type = "image/png";                     break;
			case "ppt":     $type = "application/mspowerpoint";      break;
			case "qt":      $type = "video/quicktime";               break;
			case "qti":     $type = "image/x-quicktime";             break;
			case "rar":     $type = "encoding/x-compress";           break;
			case "ra":      $type = "audio/x-pn-realaudio";          break;
			case "rm":      $type = "audio/x-pn-realaudio";          break;
			case "ram":     $type = "audio/x-pn-realaudio";          break;
			case "rtf":     $type = "application/rtf";               break;
			case "swa":     $type = "application/x-director";        break;
			case "swf":     $type = "application/x-shockwave-flash"; break;
			case "tar":     $type = "application/x-tar";             break;
			case "tgz":     $type = "application/gzip";              break;
			case "tif":     $type = "image/tiff";                    break;
			case "tiff":    $type = "image/tiff";                    break;
			case "torrent": $type = "application/x-bittorrent";      break;
			case "txt":     $type = "text/plain";                    break;
			case "wav":     $type = "audio/wav";                     break;
			case "wma":     $type = "audio/x-ms-wma";                break;
			case "wmv":     $type = "video/x-ms-wmv";                break;
			case "xls":     $type = "application/xls";               break;
			case "xml":     $type = "application/xml";               break;
			case "7z":      $type = "application/x-compress";        break;
			case "zip":     $type = "application/x-zip-compressed";  break;
	
			default:        $type = "application/force-download";    break;
		}

		$object = new httpdownload; 
		$object->filename = $file;
	 	$object->set_byfile($fullpath); //Download from a file
	 	$object->use_resume = true; //Enable Resume Mode
		$object->mime = $type;
	 	$object->download(); //Download File
	}
}
exit();
?>