*/
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.
$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;
$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');