Skip to content
This repository has been archived by the owner on Mar 2, 2022. It is now read-only.

Commit

Permalink
polyfill mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
MattIPv4 committed Jan 7, 2019
1 parent 27e6113 commit ab10cb4
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
3 changes: 3 additions & 0 deletions index.php
Expand Up @@ -16,6 +16,9 @@ function image($path)

function image_raw($path)
{
if (!function_exists("mime_content_type")) {
require_once "mimetype.php";
}
header("Content-type: " . mime_content_type("i/" . $path));
echo file_get_contents("i/" . $path);
}
Expand Down
37 changes: 37 additions & 0 deletions mimetype.php
@@ -0,0 +1,37 @@
<?php
function mime_content_type($filename)
{
$idx = explode('.', $filename);
$count_explode = count($idx);
$idx = strtolower($idx[$count_explode - 1]);

$mimet = array(

// 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',

// audio/video
'mp3' => 'audio/mpeg',
'qt' => 'video/quicktime',
'mov' => 'video/quicktime',
'mp4' => 'video/mp4',
'flv' => 'video/x-flv',

);

if (isset($mimet[$idx])) {
return $mimet[$idx];
} else {
return 'application/octet-stream';
}
}

0 comments on commit ab10cb4

Please sign in to comment.