Home » » Get mimetype of an image in php

Get mimetype of an image in php

Written By Unknown on Jumat, 15 November 2013 | 23.35

Mime type is an standard identifier of a file which indicates the type of data a file contains. It has two parts divided with a slash(/) like image/png.

The built in function of php getimagesize() gives lots of information about an image. And this function is enough to get the mime type of an image. It also returns Width and Height of the image.

GD Library is also not required to use this function.
   
$image = getimagesize("imagename.jpg");
echo $image['mime'];

It returns an array with upto 7 elements.
  Array
(
[0] => 200
[1] => 125
[2] => 2
[3] => width="125" height="125"
[bits] => 8
[channels] => 3
[mime] => image/jpeg
)
Index 0 and 1 of the array contains the width and height of the array respectively.

This function can play a big role if you are creating an image upload script and want to limit the size of the image. Suppose if you don't want to upload an image greater than 400x250.

Just check width and height of the image using getimagesize() function and return respective messages to user to upload image smaller than the required size.
Share this article :

Posting Komentar

 
Support : Creating Website | Johny Template | Mas Template
Copyright © 2011. Kumpulan Kata Broadcast Blackberry - All Rights Reserved
Template Created by Creating Website Published by Mas Template
Proudly powered by Blogger