i am trying to secure my uploader so ppl cant upload trojans/viruses best way i can see is using content type from what they upload does any1 no if theres more i can do to make this upload code more secure fanx :o)
Code:
/////UPLOAD A FILE/////
else if($mode=="upload")
{
$time=time();
$page=get_var("page");
$category=get_var("category");
$upload=get_var("upload");
$size_bytes=10485760;
$size=round($size_bytes/1048576,1);
$limitedext=array(
".jpg",".jpeg",".gif",".png",".bmp",
".mid",".mp3",".wma",".amr",
".sis",".sisx",".jar",".jad",
".3gp",".mp4",".avi",".mov",".wmv",".mpg",".mpeg"
);
$content_type=array(
"image/jpeg","image/pjpeg","image/gif","image/x-png","image/bmp",
"audio/mid","audio/mpeg","audio/x-ms-wma","audio/wav","audio/amr",
"application/octet-stream","application/x-zip-compressed",
"video/3gpp","video/mp4","video/x-msvideo","video/quicktime","video/x-ms-wmv","video/mpeg"
);
$ext=strtolower(strrchr($_FILES['filetoupload'][name],'.'));
$file_type=$_FILES['filetoupload']['type'];
$file_name=$_FILES['filetoupload']['name'];
$file_size=$_FILES['filetoupload']['size'];
$file_tmp=$_FILES['filetoupload']['tmp_name'];
$file_name=str_replace(" ","_",$file_name);
if(strpos($file_type,"image"))$type="I";
if(strpos($file_type,"audio"))$type="A";
if(strpos($file_type,"video"))$type="V";
if(strpos($file_type,"application"))$type="A";
if($upload==1){
if(!is_uploaded_file($_FILES['filetoupload']['tmp_name']))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]no file selected!![/size]";
else if(!in_array($ext,$limitedext))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]invalid file type!![/size]";
else if(!in_array($file_type,$content_type))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]content type does not match file type!![/size]";
else if($file_size>$size_bytes)$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]exceeded File size limit!! maximum $size mb.[/size]";
else if(file_exists("./downloads/$file_name"))$msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>file name already exists!!</small>";
else if($file_size){
insert(downloads,"NULL,'$type','$file_name','/downloads/$file_name','$category','$uid','$time'");
move_uploaded_file($file_tmp,"./downloads/$file_name");
$msg="<img src=\"./images/point.gif\" alt=\"[!]\"/>[size="1"]successfully uploaded $file_type file!![/size]";
}
else $msg="<img src=\"./images/error.gif\" alt=\"[x]\"/>[size="1"]unknown error!![/size]";
}
$what=Array("sitename","username","size","msg","page","category");
$with=Array($sitename,users_table("username",$uid),$size,$msg,$page,$category);
script($global_what,$global_with,$what,$with,"upload");
exit;
}
Comment