2019-08-13 09:04:36 +00:00
|
|
|
<?php
|
|
|
|
class DiskCache {
|
|
|
|
private $dir;
|
|
|
|
|
|
|
|
public function __construct($dir) {
|
|
|
|
$this->dir = basename($dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getDir() {
|
|
|
|
return $this->dir;
|
|
|
|
}
|
|
|
|
|
2019-08-13 09:15:43 +00:00
|
|
|
public function isWritable() {
|
|
|
|
return is_dir($this->dir) && is_writable($this->dir);
|
|
|
|
}
|
|
|
|
|
2019-08-13 09:04:36 +00:00
|
|
|
public function exists($filename) {
|
|
|
|
return file_exists($this->getFullPath($filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getSize($filename) {
|
|
|
|
if ($this->exists($filename))
|
|
|
|
return filesize($this->getFullPath($filename));
|
|
|
|
else
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getFullPath($filename) {
|
|
|
|
$filename = basename($filename);
|
|
|
|
|
|
|
|
return CACHE_DIR . "/" . $this->dir . "/" . $filename;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function put($filename, $data) {
|
|
|
|
return file_put_contents($this->getFullPath($filename), $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function touch($filename) {
|
|
|
|
return touch($this->getFullPath($filename));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function get($filename) {
|
|
|
|
if ($this->exists($filename))
|
|
|
|
return file_get_contents($this->getFullPath($filename));
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getMimeType($filename) {
|
|
|
|
if ($this->exists($filename))
|
|
|
|
return mime_content_type($this->getFullPath($filename));
|
|
|
|
else
|
|
|
|
return null;
|
|
|
|
}
|
2019-08-13 09:20:53 +00:00
|
|
|
|
|
|
|
public function send($filename) {
|
|
|
|
return send_local_file($this->getFullPath($filename));
|
|
|
|
}
|
2019-08-13 09:39:21 +00:00
|
|
|
|
|
|
|
static public function getUrl($filename) {
|
|
|
|
return get_self_url_prefix() . "/public.php?op=cached_url&file=" . $filename;
|
|
|
|
}
|
2019-08-13 09:04:36 +00:00
|
|
|
}
|