Example #1
0
 /**
  * @return BaseMimeTypes
  */
 private static function instance()
 {
     if (self::$instance === null) {
         self::$instance = new BaseMimeTypes();
     }
     return self::$instance;
 }
Example #2
0
<?php

$imageTypes = loadPicFile("conf/app.json")["image_types"];
$allImageTypes = array();
foreach ($imageTypes as $imageType) {
    $allImageTypes = array_merge($allImageTypes, array_merge([$imageType], MrMime::getOtherExtensions($imageType)));
}
return array_map("strtolower", $allImageTypes);
<?php

/** @var string $filename */
$allowedImageTypes = loadPicFile("helpers/imagetypes.php");
$originalExtension = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
if (!in_array($originalExtension, $allowedImageTypes)) {
    sendError(400);
}
$mimeType = MrMime::extensionToMimeType($originalExtension);
$actualMimeType = MrMime::resolveMimeType($filename);
if ($actualMimeType !== $mimeType) {
    Logger::warning("error", "Invalid image found.", array("filename" => $filename, "expectedMimeType" => $mimeType, "actualMimeType" => $actualMimeType));
    sendError(500);
}
switch ($mimeType) {
    case "image/jpeg":
        $normalisedExtension = "jpeg";
        break;
    default:
        $normalisedExtension = $originalExtension;
        break;
}
return array($normalisedExtension, $mimeType);