<?php class My_Mime { function getMimetypeOnExt($ext) { $mimetypes = array( 'gif' => 'image/gif', 'jpeg' => 'image/jpeg', 'jpg' => 'image/jpeg', 'png' => 'image/png', 'css' => 'text/css', 'html' => 'text/html', 'htm' => 'text/html', 'txt' => 'text/plain', 'js' => 'application/javascript', 'json' => 'application/json', 'mathml' => 'application/mathml+xml', 'doc' => 'application/msword', 'pdf' => 'application/pdf', 'zip' => 'application/zip', 'exe' => 'application/x-msdownload', 'gz' => 'application/x-gzip', 'tgz' => 'application/x-gzip', ... ); $ext = strtolower(trim($ext)); if (isset($mimetypes[$ext])) { return $mimetypes[$ext]; } else { return false; } } }
Listing 24.1. Klasa My_Mime
Rozdział 24. Zapisywanie w bazie danych plików binarnych