개발 Q&A

제목 mime_content_type 함수 관련 문의입니다.
글쓴이 amkor 작성시각 2015/10/05 10:28:42
댓글 : 1 추천 : 0 스크랩 : 0 조회수 : 12167   RSS
mime_content_type 함수 php.ini에서 보니깐..
 
if(!function_exists('mime_content_type')) {
	function mime_content_type($file) {
		return trim(exec("file -bi ".escapeshellarg($file)));
	}
}

=====================================================
 
if(!function_exists('mime_content_type')) {
	function mime_content_type($filename) {

        $mime_types = array(

            'txt' => 'text/plain',
            'htm' => 'text/html',
            'html' => 'text/html',
            'php' => 'text/html',
            'css' => 'text/css',
            'js' => 'application/javascript',
            'json' => 'application/json',
            'xml' => 'application/xml',
            'swf' => 'application/x-shockwave-flash',
            'flv' => 'video/x-flv',

            // images
            'png' => 'image/png',
            'jpe' => 'image/jpeg',
            'jpeg' => 'image/jpeg',
            'jpg' => 'image/jpeg',
            'gif' => 'image/gif',
            'bmp' => 'image/bmp',
            'ico' => 'image/vnd.microsoft.icon',
            'tiff' => 'image/tiff',
            'tif' => 'image/tiff',
            'svg' => 'image/svg+xml',
            'svgz' => 'image/svg+xml',

            // archives
            'zip' => 'application/zip',
            'rar' => 'application/x-rar-compressed',
            'exe' => 'application/x-msdownload',
            'msi' => 'application/x-msdownload',
            'cab' => 'application/vnd.ms-cab-compressed',

            // audio/video
            'mp3' => 'audio/mpeg',
            'qt' => 'video/quicktime',
            'mov' => 'video/quicktime',

            // adobe
            'pdf' => 'application/pdf',
            'psd' => 'image/vnd.adobe.photoshop',
            'ai' => 'application/postscript',
            'eps' => 'application/postscript',
            'ps' => 'application/postscript',

            // ms office
            'doc' => 'application/msword',
            'rtf' => 'application/rtf',
            'xls' => 'application/vnd.ms-excel',
            'ppt' => 'application/vnd.ms-powerpoint',

            // open office
            'odt' => 'application/vnd.oasis.opendocument.text',
            'ods' => 'application/vnd.oasis.opendocument.spreadsheet',
        );

        $ext = strtolower(array_pop(explode('.',$filename)));
        if (array_key_exists($ext, $mime_types)) {
            return $mime_types[$ext];
        }
        elseif (function_exists('finfo_open')) {
            $finfo = finfo_open(FILEINFO_MIME);
            $mimetype = finfo_file($finfo, $filename);
            finfo_close($finfo);
            return $mimetype;
        }
        else {
            return 'application/octet-stream';
        }
    }
}





이 2가지가 있는데요... 

무슨 차이점이 있는건가요? php.ini 봐도 모르겠네요 ㅠ,ㅠ 이놈의 영어 독해력 ㅠ,ㅠ

참고로 업로드 에러가 나서 mime_content_type 함수를 보니 위에 예시에 나와있는 2번째에서 1번째로 바꾸었더니

잘됬었습니다.

그냥 지나칠수 없기에 공부 하는중 이렇게 질문 드립니다.,

 
 다음글 업데이트 쿼리문 질문드립니다. (1)
 이전글 팝업창이 안뜹니다. (2)

댓글

변종원(웅파) / 2015/10/05 10:45:21 / 추천 0
첫번째 것은 리눅스 콘솔 명령어인  file을 사용한 것이고
두번째는 finfo_open라는 php함수를 사용했네요. 그 결과중에서 배열과 맞는걸 찾도록 되어 있구요.

두번째가 좀더 안정적일 수 있습니다. 특정 마임타입에 대한 체크까지 들어가 있는 로직이니까요.
첫번째는 그냥 마임타입만 리턴하는거구요.