-
Notifications
You must be signed in to change notification settings - Fork 0
/
jqueryFileTree.php
executable file
·70 lines (57 loc) · 2.32 KB
/
jqueryFileTree.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
if( !array_key_exists('HTTP_REFERER', $_SERVER) ) exit('No direct script access allowed');
/**
* jQuery File Tree PHP Connector
*
* Version 1.1.0
*
* @author - Cory S.N. LaViska A Beautiful Site (http://abeautifulsite.net/)
* @author - Dave Rogers - https://github.com/daverogers/jQueryFileTree
*
* History:
*
* 1.1.1 - SECURITY: forcing root to prevent users from determining system's file structure (per DaveBrad)
* 1.1.0 - adding multiSelect (checkbox) support (08/22/2014)
* 1.0.2 - fixes undefined 'dir' error - by itsyash (06/09/2014)
* 1.0.1 - updated to work with foreign characters in directory/file names (12 April 2008)
* 1.0.0 - released (24 March 2008)
*
* Output a list of files for jQuery File Tree
*/
/**
* filesystem root - USER needs to set this!
* -> prevents debug users from exploring system's directory structure
* ex: $root = $_SERVER['DOCUMENT_ROOT'];
*/
//$root = null;
$root = $_SERVER['DOCUMENT_ROOT'];
if( !$root ) exit("ERROR: Root filesystem directory not set in jqueryFileTree.php");
$postDir = rawurldecode($root.(isset($_POST['dir']) ? $_POST['dir'] : null ));
// set checkbox if multiSelect set to true
$checkbox = ( isset($_POST['multiSelect']) && $_POST['multiSelect'] == 'true' ) ? "<input type='checkbox' />" : null;
$onlyFolders = ( isset($_POST['onlyFolders']) && $_POST['onlyFolders'] == 'true' ) ? true : false;
$onlyFiles = ( isset($_POST['onlyFiles']) && $_POST['onlyFiles'] == 'true' ) ? true : false;
if( file_exists($postDir) ) {
$files = scandir($postDir);
$returnDir = substr($postDir, strlen($root));
natcasesort($files);
if( count($files) > 2 ) { // The 2 accounts for . and ..
echo "<ul class='jqueryFileTree'>";
foreach( $files as $file ) {
$htmlRel = htmlentities($returnDir . $file,ENT_QUOTES);
$htmlName = htmlentities($file);
$ext = preg_replace('/^.*\./', '', $file);
if( file_exists($postDir . $file) && $file != '.' && $file != '..' ) {
if( is_dir($postDir . $file) ) {
if (!$onlyFiles)
echo "<li class='directory collapsed'>{$checkbox}<a rel='" .$htmlRel. "/'>" . $htmlName . "</a></li>";
} else {
if (!$onlyFolders)
echo "<li class='file ext_{$ext}'>{$checkbox}<a rel='" . $htmlRel . "'>" . $htmlName . "</a></li>";
}
}
}
echo "</ul>";
}
}
?>