테스트 사이트 - 개발 중인 베타 버전입니다

파일이름의 확장자로 파일 종류를 확인하는 함수

· 18년 전 · 2372
파일이름의 확장자로 파일 종류를 확인하는 함수입니다.
미디어스킨 또는 이미지 관련스킨에 유용할듯해서 올립니다.


function file_type($filename)
{
$tmp = explode(".", $filename);
$ext = trim($tmp[count($tmp)-1]);

$type_image = "jpg|jpeg|gif|bmp|pcx|png";
$type_compress = "zip|alz|gz|tar|z|rar|ace|bz|bz2";
$type_text = "txt|text|rtf|2b";
$type_html = "htm|html";
$type_hwp = "hwp|h30";
$type_exe = "exe";
$type_font = "ttf";
$type_movie = "avi|mpg|mpeg|mqv|asf|wmv|mov";
$type_sound = "wav|mp3|mid|wma";

if(preg_match("/($type_image)/i",$ext))
$file_type = 'image';
else if(preg_match("/($type_compress)/i",$ext))
$file_type = 'compress';
else if(preg_match("/($type_text)/i",$ext))
$file_type = 'text';
else if(preg_match("/($type_html)/i",$ext))
$file_type = 'html';
else if(preg_match("/($type_hwp)/i",$ext))
$file_type = 'hwp';
else if(preg_match("/($type_exe)/i",$ext))
$file_type = 'exe';
else if(preg_match("/($type_font)/i",$ext))
$file_type = 'font';
else if(preg_match("/($type_movie)/i",$ext))
$file_type = 'movie';
else if(preg_match("/($type_sound)/i",$ext))
$file_type = 'sound';
else
$file_type = 'unknown';

return $file_type;
}




// phpschool에서 펌<div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>

댓글 작성

댓글을 작성하시려면 로그인이 필요합니다.

로그인하기

게시글 목록

번호 제목
24900
24899
24898
24897
24896
24895
24894
24893
24892
24891
24890
24889
24888
24887
24886
11687
24885
24884
24883
24882
24881
24879
24878
24877
24875
24874
24873
24872
24871
11683
11662
11659
29136
11647
11644
11641
11634
11632
29135
11631
11628
24870
24869
24868
24867
24866
24865
24864
24863
24862
24861
24860
11627
24859
24858
24856
24855
24854
24853
24852
29130
11625
11622
11617
11604
11596
11591
11586
29128
11583
11579
11578
11574
11566
11565
11562
11561
29125
11558
11556
11533
11529
29118
11526
11519
29115
11518
11516
11515
11509
11508
29112
11496
29109
29106
11495
11488
11486
11483
11471