2013-07-27 02:15:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
use Entities\Image;
|
|
|
|
use Entities\Track;
|
|
|
|
use Illuminate\Support\Facades\App;
|
2013-09-01 22:04:30 +02:00
|
|
|
use Illuminate\Support\Facades\Redirect;
|
2013-07-27 02:15:07 +02:00
|
|
|
|
|
|
|
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-09-01 12:44:32 +02:00
|
|
|
$response = Response::make('', 200);
|
2013-07-27 05:00:45 +02:00
|
|
|
$filename = $image->getFile($coverType['id']);
|
|
|
|
|
2013-09-01 22:04:30 +02:00
|
|
|
if (!is_file($filename)) {
|
|
|
|
$redirect = URL::to('/images/icons/profile_' . Image::$ImageTypes[$coverType['id']]['name'] . '.png');
|
|
|
|
return Redirect::to($redirect);
|
|
|
|
}
|
|
|
|
|
2013-09-01 12:44:32 +02:00
|
|
|
if (Config::get('app.sendfile')) {
|
|
|
|
$response->header('X-Sendfile', $filename);
|
|
|
|
} else {
|
|
|
|
$response->header('X-Accel-Redirect', $filename);
|
2013-07-27 05:00:45 +02:00
|
|
|
}
|
|
|
|
|
2013-09-01 12:44:32 +02:00
|
|
|
$response->header('Content-Disposition', 'filename="' . $filename . '"');
|
|
|
|
$response->header('Content-Type', 'image/png');
|
2013-07-27 05:00:45 +02:00
|
|
|
|
2013-09-01 13:26:56 +02:00
|
|
|
$lastModified = filemtime($filename);
|
|
|
|
|
2013-09-01 21:08:28 +02:00
|
|
|
$response->header('Last-Modified', $lastModified);
|
|
|
|
$response->header('Cache-Control', 'max-age=' . (60 * 60 * 24 * 7));
|
2013-09-01 13:26:56 +02:00
|
|
|
|
2013-09-01 12:44:32 +02:00
|
|
|
return $response;
|
2013-07-27 02:15:07 +02:00
|
|
|
}
|
|
|
|
}
|