Pony.fm/app/controllers/ImagesController.php

31 lines
780 B
PHP
Raw Normal View History

2013-07-27 02:15:07 +02:00
<?php
use Entities\Image;
use Entities\Track;
use Illuminate\Support\Facades\App;
class ImagesController extends Controller {
public function getImage($id, $type) {
2013-07-28 06:37:32 +02:00
$coverType = Image::getImageTypeFromName($type);
2013-07-27 02:15:07 +02:00
if ($coverType == null)
App::abort(404);
$image = Image::find($id);
if (!$image)
App::abort(404);
2013-07-27 05:00:45 +02:00
$filename = $image->getFile($coverType['id']);
$lastModified = filemtime($filename);
if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $lastModified == $_SERVER['HTTP_IF_MODIFIED_SINCE']) {
header('HTTP/1.0 304 Not Modified');
exit();
}
header('Last-Modified: ' . $lastModified);
header('Cache-Control: max-age=' . (60 * 60 * 24 * 7));
return File::inline($filename, $image->mime, $image->filename);
2013-07-27 02:15:07 +02:00
}
}