<?php
require_once("Security.php");
class File{
function encodePath($path){
global $sitekey;
return Security::encrypt($path,$sitekey);
}
function decodePath($encPath){
global $sitekey;
return Security::decrypt($encPath,$sitekey);
}
function getFile($encPath,$bEnc=true,$bAttach=false){
$mimetypes = array (
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'kar' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'ra' => 'audio/x-realaudio',
'wav' => 'audio/x-wav',
'asx' => 'video/x-ms-asf',
'pdf' => 'application/pdf',
'rtf' => 'application/rtf',
'asc' => 'text/plain',
'txt' => 'text/plain',
'log' => 'text/plain',
'xml' => 'text/xml',
'html' => 'text/hml',
'htm' => 'text/hml',
'bz2' => 'application/x-bzip2',
'gz' => 'application/x-gzip',
'tgz' => 'application/x-gzip',
'zip' => 'application/zip',
'dvi' => 'application/x-dvi',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo'
);
if($bEnc)
$path=File::decodePath($encPath);
else
$path=$encPath;
if(!file_exists($path))
die("File $path not exist. It can't be get");
$aFile=explode(".",$path);
$ext=$aFile[count($aFile)-1];
$mime=$mimetypes[$ext];
if($mime=="")
$mime="application/x-download";
header("Content-Description: File Transfer");
header( "Content-type: $mime" );
if($bAttach)
header("Content-Disposition: attachment; filename=".basename($path));
@readfile($path);
}
function getUrl($encPath,$bEnc=true,$bAttach=false){
$mimetypes = array (
'mid' => 'audio/midi',
'midi' => 'audio/midi',
'kar' => 'audio/midi',
'mpga' => 'audio/mpeg',
'mp2' => 'audio/mpeg',
'mp3' => 'audio/mpeg',
'aif' => 'audio/x-aiff',
'aiff' => 'audio/x-aiff',
'aifc' => 'audio/x-aiff',
'ram' => 'audio/x-pn-realaudio',
'rm' => 'audio/x-pn-realaudio',
'ra' => 'audio/x-realaudio',
'wav' => 'audio/x-wav',
'asx' => 'video/x-ms-asf',
'pdf' => 'application/pdf',
'rtf' => 'application/rtf',
'asc' => 'text/plain',
'txt' => 'text/plain',
'log' => 'text/plain',
'xml' => 'text/xml',
'html' => 'text/hml',
'htm' => 'text/hml',
'bz2' => 'application/x-bzip2',
'gz' => 'application/x-gzip',
'tgz' => 'application/x-gzip',
'zip' => 'application/zip',
'dvi' => 'application/x-dvi',
'gif' => 'image/gif',
'jpeg' => 'image/jpeg',
'jpg' => 'image/jpeg',
'jpe' => 'image/jpeg',
'png' => 'image/png',
'mpeg' => 'video/mpeg',
'mpg' => 'video/mpeg',
'mpe' => 'video/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'avi' => 'video/x-msvideo'
);
if($bEnc)
$path=File::decodePath($encPath);
else
$path=$encPath;
if(file_exists($path)){
$aFile=explode(".",$path);
$ext=$aFile[count($aFile)-1];
$mime=$mimetypes[$ext];
if($mime=="")
$mime="application/x-download";
header("Content-Description: File Transfer");
header( "Content-type: $mime" );
if($bAttach)
header("Content-Disposition: attachment; filename=".basename($path));
@readfile($path);
}else
die("File not exist");
}
}
?>