3 class ChameleonFileBrowser
{
9 var $founddirs = array();
10 var $foundfiles = array();
12 function ChameleonFileBrowser() {
13 $this->IMAGE_TYPES
= array('jpeg', 'jpg', 'gif', 'png');
15 $tmp = explode('/', str_replace('\\', '/', __FILE__
));
18 $this->root
= implode('/', $tmp);
20 $this->path
= $this->sanitisepath($_GET['path']);
21 $this->dir
= $this->root
. '/' . $this->path
;
24 function sanitisepath($path) {
25 if ($path == 'root') {
29 if (substr($path, 0, 3) != 'pix') {
30 $this->send('<chameleon_error>Not a valid directory</chameleon_error>');
33 return preg_replace('/[.]+/', '', $path);
36 function isimage($file) {
37 if (strpos($file, '.') === false) {
40 return in_array(array_pop(explode('.', $file)), $this->IMAGE_TYPES
);
43 function readfiles() {
44 if (!is_dir($this->dir
)) {
45 $this->send('<chameleon_error>Not a valid directory</chameleon_error>');
48 $handle = opendir($this->dir
);
49 while (false !== ($file = readdir($handle))) {
50 if ($file == '.' ||
$file == '..') {
53 if (is_dir($this->dir
. '/' . $file)) {
54 $this->founddirs
[] = $file;
55 } else if ($this->isimage($file)) {
56 $this->foundfiles
[] = $file;
61 sort($this->founddirs
, SORT_STRING
);
62 sort($this->foundfiles
, SORT_STRING
);
66 function sendfiles() {
67 $out = "<files path=\"$this->path\">\n";
68 foreach ($this->founddirs
as $file) {
69 $out .= " <file type=\"dir\">$this->path/$file</file>\n";
71 foreach ($this->foundfiles
as $file) {
72 $out .= " <file type=\"img\">$this->path/$file</file>\n";
80 header("Content-type: application/xml; charset=utf-8");