'MIME'에 해당되는 글 1건
File MIME :: 2006/07/09 00:48
파일 첨부시 $_FILES 변수로 파일의 mime 값이 함께 넘어온다.
이 변수를 통해 mime 값을 손쉽게 얻어 활용을 할 수 있었으나,
정작 서버에 존재하는 파일의 mime 값을 구하기는 쉽지 않았다.
케살님과 대화를 하던도중 몇 년 전에 짜 놓은 소스라면서 보여주신다.
근데 그 소스...대화창 닫히면서 저장을 못했다.ㅠ_ㅠ
그래도 명령어는 대충 기억이 난다.
예시 명령 수행 결과
[root@nios]$ file -bi virtual_user.txt
text/plain; charset=us-ascii
[root@nios]$ cp virtual_user.txt virtual_user.txt.tar.gz
[root@nios]$ file -bi virtual_user.txt.tar.gz
text/plain; charset=us-ascii
옵션 설명
file의 매뉴얼을 살펴보면 아래와 같은 옵션 설명이 있다.
-i, --mime
Causes the file command to output mime type strings rather than
the more traditional human readable ones. Thus it may say
``text/plain; charset=us-ascii'' rather than ``ASCII text''. In
order for this option to work, file changes the way it handles
files recognised by the command itself (such as many of the text
file types, directories etc), and makes use of an alternative
magic file. (See FILES section, below).
예시 함수
/**
* get file's mime-text
*
* @author Nios (nios@nios.info)
* @param (string) filename, file name with full-path
* @return (string) mime-text
*/
function get_file_mime($filename)
{
if(is_file($filename) === false) return false;
$buffer = "";
$fp = popen("file -bi " . $filename, "r");
while(feof($fp) === false)
{
$buffer .= fgets($fp, 4096);
}
pclose($fp);
return array_pop(array_reverse(explode(";", $buffer)));
}
크하하 위 소스 사실 테스트 한 번도 안해봤음... 다음에 해봐야겠당...
대충 그냥 만들어 놓기만...-┏






