diff options
author | Olivier Gayot <duskcoder@gmail.com> | 2015-01-13 21:51:36 +0100 |
---|---|---|
committer | Olivier Gayot <duskcoder@gmail.com> | 2015-01-13 21:51:36 +0100 |
commit | 3bdf0b110f4c5880307e871fbcdb737ee6f915da (patch) | |
tree | 94551a8b1d1d65e5072146e5704dc28188027380 | |
parent | 575836eb24be7ddbbb2d03e5c5de95f1a6b9c81e (diff) |
added a way to specify the download and count directories
The constructor of the class takes them as optional arguments
Signed-off-by: Olivier Gayot <duskcoder@gmail.com>
-rw-r--r-- | PHP_DW.php | 29 |
1 files changed, 24 insertions, 5 deletions
@@ -1,19 +1,30 @@ <?php class PHP_DW { - private $base_dw = 'downloads'; - private $base_count = '.count'; + private $dw_dir = 'downloads'; + private $cnt_dir = '.count'; + + function __construct($dw_dir = false, $cnt_dir = false) { + + if ($dw_dir) { + $this->dw_dir = $dw_dir; + } + + if ($cnt_dir) { + $this->cnt_dir = $cnt_dir; + } + } private function __get_full_path($path) { if (basename($path) !== $path) { return null; } - return $this->base_dw . '/' . $path; + return $this->dw_dir . '/' . $path; } private function __incr_count($filename) { - $fh = @fopen($this->base_count . '/' . $filename . '.cnt', "a+"); + $fh = @fopen($this->cnt_dir . '/' . $filename . '.cnt', "a+"); if (is_resource($fh) and flock($fh, LOCK_EX)) { rewind($fh); @@ -54,7 +65,7 @@ class PHP_DW { if (!$this->__get_full_path($filename)) return 0; - $fh = @fopen($this->base_count . '/' . $filename . '.cnt', "r"); + $fh = @fopen($this->cnt_dir . '/' . $filename . '.cnt', "r"); if (!is_resource($fh)) return 0; @@ -65,5 +76,13 @@ class PHP_DW { return $count; } + + public function get_count_dir() { + return $this->cnt_dir; + } + + public function get_download_dir() { + return $this->dw_dir; + } } ?> |