summaryrefslogtreecommitdiff
path: root/PHP_DW.php
diff options
context:
space:
mode:
authorOlivier Gayot <duskcoder@gmail.com>2015-01-13 21:51:36 +0100
committerOlivier Gayot <duskcoder@gmail.com>2015-01-13 21:51:36 +0100
commit3bdf0b110f4c5880307e871fbcdb737ee6f915da (patch)
tree94551a8b1d1d65e5072146e5704dc28188027380 /PHP_DW.php
parent575836eb24be7ddbbb2d03e5c5de95f1a6b9c81e (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>
Diffstat (limited to 'PHP_DW.php')
-rw-r--r--PHP_DW.php29
1 files changed, 24 insertions, 5 deletions
diff --git a/PHP_DW.php b/PHP_DW.php
index 8c20cba..d119082 100644
--- a/PHP_DW.php
+++ b/PHP_DW.php
@@ -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;
+ }
}
?>