From: Christian Weiske Date: Tue, 8 Apr 2014 15:58:20 +0000 (+0200) Subject: add redirect config option X-Git-Tag: v0.1.0~28 X-Git-Url: https://git.cweiske.de/phancap.git/commitdiff_plain/e37dfddb07d225e3cd0a0527eea65078f13fa96a add redirect config option --- diff --git a/src/phancap/Config.php b/src/phancap/Config.php index 4d7c7a0..1bb4379 100644 --- a/src/phancap/Config.php +++ b/src/phancap/Config.php @@ -29,6 +29,16 @@ class Config */ public $access = true; + /** + * Redirect the browser to the cache URL. + * If disabled, the file is directly delivered. + * + * Helpful for debugging since it does not change the browser's URL. + * + * @var boolean + */ + public $redirect = true; + /** * How long requests with an old timestamp may be used. * 2 days default. diff --git a/src/phancap/Image.php b/src/phancap/Image.php index 6750cfc..ab3868e 100644 --- a/src/phancap/Image.php +++ b/src/phancap/Image.php @@ -12,6 +12,19 @@ class Image $this->name = $name; } + public function getMimeType() + { + $ext = substr($this->name, -4); + if ($ext == '.jpg') { + return 'image/jpeg'; + } else if ($ext == '.png') { + return 'image/png'; + } else if ($ext == '.png') { + return 'application/pdf'; + } + return 'application/octet-stream'; + } + public function getPath() { return $this->config->cacheDir . $this->name; diff --git a/www/get.php b/www/get.php index 1da3e8a..15463e4 100644 --- a/www/get.php +++ b/www/get.php @@ -40,8 +40,13 @@ $rep = new Repository(); $rep->setConfig($config); try { $img = $rep->getImage($options); - header('HTTP/1.0 302 Found'); - header('Location: ' . $img->getUrl()); + if ($config->redirect) { + header('HTTP/1.0 302 Found'); + header('Location: ' . $img->getUrl()); + } else { + header('Content-type: ' . $img->getMimeType()); + readfile($img->getPath()); + } } catch (\Exception $e) { //FIXME: handle 404s and so properly header('HTTP/1.0 500 Internal Server error');