Reply to Re: PHP Question: Getting File Mime Type

Re: PHP Question: Getting File Mime Type new!
by colin, 17 years, 8 months ago
Look at the code of the class. There are several methods. One -the last one in the code below- uses the compilation MIME magic, now replaced by the fileinfo extension .
 // we try to retrieve the MIME type
$info = getimagesize($this->file_src_pathname);
$this->file_src_mime = (array_key_exists('mime', $info) ? $info['mime'] : NULL);
// if we don't have a MIME type, we attempt to retrieve it the old way
if (empty($this->file_src_mime)) {
  $mime = (array_key_exists(2, $info) ? $info[2] : NULL); // 1 = GIF, 2 = JPG, 3 = PNG
  $this->file_src_mime = ($mime==1 ? 'image/gif' : ($mime==2 ? 'image/jpeg' : ($mime==3 ? 'image/png' : NULL)));
}
// if we still don't have a MIME type, we attempt to retrieve it otherwise
  if (empty($this->file_src_mime) && function_exists('mime_content_type')) {
  $this->file_src_mime = mime_content_type($this->file_src_pathname);
} 
Reply

Your reply

Name *
Email 
Title *
Text *
CAPTCHA image
Enter the code displayed on the image:
Click on the image to generate another one if it is hard to read it. The case is important