<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

function file_type($filename){
	$file = fopen($filename, "rb");  
    $bin = fread($file, 2);
    fclose($file);
	$strInfo = @unpack("C2chars", $bin);
    $typeCode = intval($strInfo['chars1'].$strInfo['chars2']);
	$fileType = '';
	switch ($typeCode)  
    {
		case 11590:
			$fileType = 'exe';  
			break;
		case 5075:
			$fileType = 'zip';
			break;
        case 255216:
            $fileType = 'jpg';  
            break;  
        case 7173:  
            $fileType = 'gif';  
            break;
        case 13780:  
            $fileType = 'png';  
            break;  
        default:  
            $fileType = '';  
    }
	return $fileType;
}









