맛집 여행 캠핑 일상 생활

크롬브라우저 Content-Disposition: inline bmp 이미지 문제 본문

LAMP

크롬브라우저 Content-Disposition: inline bmp 이미지 문제

영은파더♥ 2016. 9. 7. 15:54

크롬브라우저 Content-Disposition: inline bmp 이미지 문제


PHP 에서 서버의 이미지 파일을 브라우저에 바로 보여주는 소스인데,

문제는 BMP 이미지가 브라우저에 바로 보여지지 않고 다운로드가 되는 문제점이 있다.


function image_view($img_path) {

$IMAGE_PATH = $img_path;

$IMAGE_SIZE = getimagesize($IMAGE_PATH);

$fp = fopen($IMAGE_PATH,"rb");

if($fp) {

$FILENAME = 'download.'.strtolower(substr($IMAGE_PATH,strlen($IMAGE_PATH)-3,3));

header("Content-Type: ".$IMAGE_SIZE['mime']);

header("Content-Disposition: inline; filename=$FILENAME");

header("Content-Length: ".filesize($IMAGE_PATH));

fpassthru($fp);

}

fclose($fp);

}


$IMAGE_SIZE['mime'] 의 값을 찍어보면 "image/x-ms-bmp" 라고 나온다.

이 값을 "image/bmp" 로 바꿔주면 브라우저에서 바로 보여진다.


if($IMAGE_SIZE[2] == 6) { // bmp

header("Content-Type: image/bmp");

}

else {

header("Content-Type: ".$IMAGE_SIZE['mime']);

}

위와 같이 수정해주면 해결이 된다.


Trackback : | Comments :