directory uitlezen
ik wil met behulp van dit script een directory uitlezen.
Code (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<?
/*
*/
/*
*********************** CONFIGURE BELOW THIS LINE ***********************
*/
/*
** CSS (Style Sheet) Definition Begginning
*/
/*
** CSS (Style Sheet) Definition Finished
*/
/*
** Display Disk Space Usagae and Free
*/
$scriptStats = "1"; // 1 for Yes - 0 for No
/*
*********************** DO NOT MODIFY BELOW THIS LINE ***********************
*/
function dirHeader() {
$content = "<table width=100% nowrap>";
return $content;
}
function dirTable() {
$content = "<tr><td><b><font size=-1>Type</font></b></td><td width=50%><b><font size=-1>Name</font></b></td><td><b><font size=-1>Size</font></b></td><td><b><font size=-1>Modified</font></b></td></tr>";
return $content;
}
function dirFooter() {
$content = "</table>";
return $content;
}
function fType($file) {
$varFileType = filetype($file);
if($varFileType != "dir") {
$curdir = getcwd();
$pInfo = pathinfo("$curdir/$file");
$varFileType = $pInfo["extension"];
}
return $varFileType;
}
function fileView($file) {
$varType = strtolower(fType($file));
$varJSSettings = "width=300,height=300,resizable=1,scrollbars=1,menubar=0,status=0,titlebar=0,toolbar=0,hotkeys=0,locationbar=0";
$txtArray[] = "txt";
$txtArray[] = "nfo";
$txtArray[] = "diz";
$txtArray[] = "now";
$txtArray[] = "bmp";
$txtArray[] = "jpg";
$txtArray[] = "gif";
$txtArray[] = "doc";
$txtArray[] = "1st";
$txtArray[] = "now";
$txtArray[] = "me";
if(in_array($varType, $txtArray)) {
$content = " - (<a href=\"#\" onClick=\"window.open('$file', 'viewer','$varJSSettings');\">view</a>)";
}
return $content;
}
function display_size($file_size){
if($file_size >= 1073741824) {
$file_size = round($file_size / 1073741824 * 100) / 100 . "g";
} elseif($file_size >= 1048576) {
$file_size = round($file_size / 1048576 * 100) / 100 . "m";
} elseif($file_size >= 1024) {
$file_size = round($file_size / 1024 * 100) / 100 . "k";
} else {
$file_size = $file_size . "b";
}
return $file_size;
}
function dirGather() {
$handle=opendir(".");
$content = "";
//while (false!=($file = readdir($handle))) {
while ($file = readdir($handle)) {
if(($file != "index.txt") && ($file != "index.php")) {
$filetype = fType($file);
if($filetype == "dir") {
$dirtext[] = "$file";
} else {
$context[] = "$file";
}
}
}
if($dirtext) {
sort($dirtext);
for($i=0; $i<count($dirtext); $i++) {
$file = $dirtext[$i];
$lastchanged = filectime($file);
$changeddate = date("d-m-Y H:i:s", $lastchanged);
$filesize = display_size(filesize($file));
$filetype = fType($file);
$viewfile = fileView($file);
$content .= "<tr><td><font size=-1>$filetype</font></td>";
$content .= "<td><font size=-1><a href=\"$file\">$file</a> $viewfile</font></td>";
$content .= "<td><font size=-1>$filesize</font></td>";
$content .= "<td><font size=-1>$changeddate</font></td></tr>";
}
}
if($context) {
sort($context);
for($i=0; $i<count($context); $i++) {
$file = $context[$i];
$lastchanged = filectime($file);
$changeddate = date("d-m-Y H:i:s", $lastchanged);
$filesize = display_size(filesize($file));
$filetype = fType($file);
$viewfile = fileView($file);
$content .= "<tr><td><font size=-1>$filetype</font></td>";
$content .= "<td><font size=-1><a href=\"$file\">$file</a> $viewfile</font></td>";
$content .= "<td><font size=-1>$filesize</font></td>";
$content .= "<td><font size=-1>$changeddate</font></td></tr>";
}
}
return $content;
}
function diskStats($scriptStats) {
if($scriptStats) {
// $diskTotal = display_size(disk_total_space("/"));
print($content);
}
}
?>
/*
*/
/*
*********************** CONFIGURE BELOW THIS LINE ***********************
*/
/*
** CSS (Style Sheet) Definition Begginning
*/
/*
** CSS (Style Sheet) Definition Finished
*/
/*
** Display Disk Space Usagae and Free
*/
$scriptStats = "1"; // 1 for Yes - 0 for No
/*
*********************** DO NOT MODIFY BELOW THIS LINE ***********************
*/
function dirHeader() {
$content = "<table width=100% nowrap>";
return $content;
}
function dirTable() {
$content = "<tr><td><b><font size=-1>Type</font></b></td><td width=50%><b><font size=-1>Name</font></b></td><td><b><font size=-1>Size</font></b></td><td><b><font size=-1>Modified</font></b></td></tr>";
return $content;
}
function dirFooter() {
$content = "</table>";
return $content;
}
function fType($file) {
$varFileType = filetype($file);
if($varFileType != "dir") {
$curdir = getcwd();
$pInfo = pathinfo("$curdir/$file");
$varFileType = $pInfo["extension"];
}
return $varFileType;
}
function fileView($file) {
$varType = strtolower(fType($file));
$varJSSettings = "width=300,height=300,resizable=1,scrollbars=1,menubar=0,status=0,titlebar=0,toolbar=0,hotkeys=0,locationbar=0";
$txtArray[] = "txt";
$txtArray[] = "nfo";
$txtArray[] = "diz";
$txtArray[] = "now";
$txtArray[] = "bmp";
$txtArray[] = "jpg";
$txtArray[] = "gif";
$txtArray[] = "doc";
$txtArray[] = "1st";
$txtArray[] = "now";
$txtArray[] = "me";
if(in_array($varType, $txtArray)) {
$content = " - (<a href=\"#\" onClick=\"window.open('$file', 'viewer','$varJSSettings');\">view</a>)";
}
return $content;
}
function display_size($file_size){
if($file_size >= 1073741824) {
$file_size = round($file_size / 1073741824 * 100) / 100 . "g";
} elseif($file_size >= 1048576) {
$file_size = round($file_size / 1048576 * 100) / 100 . "m";
} elseif($file_size >= 1024) {
$file_size = round($file_size / 1024 * 100) / 100 . "k";
} else {
$file_size = $file_size . "b";
}
return $file_size;
}
function dirGather() {
$handle=opendir(".");
$content = "";
//while (false!=($file = readdir($handle))) {
while ($file = readdir($handle)) {
if(($file != "index.txt") && ($file != "index.php")) {
$filetype = fType($file);
if($filetype == "dir") {
$dirtext[] = "$file";
} else {
$context[] = "$file";
}
}
}
if($dirtext) {
sort($dirtext);
for($i=0; $i<count($dirtext); $i++) {
$file = $dirtext[$i];
$lastchanged = filectime($file);
$changeddate = date("d-m-Y H:i:s", $lastchanged);
$filesize = display_size(filesize($file));
$filetype = fType($file);
$viewfile = fileView($file);
$content .= "<tr><td><font size=-1>$filetype</font></td>";
$content .= "<td><font size=-1><a href=\"$file\">$file</a> $viewfile</font></td>";
$content .= "<td><font size=-1>$filesize</font></td>";
$content .= "<td><font size=-1>$changeddate</font></td></tr>";
}
}
if($context) {
sort($context);
for($i=0; $i<count($context); $i++) {
$file = $context[$i];
$lastchanged = filectime($file);
$changeddate = date("d-m-Y H:i:s", $lastchanged);
$filesize = display_size(filesize($file));
$filetype = fType($file);
$viewfile = fileView($file);
$content .= "<tr><td><font size=-1>$filetype</font></td>";
$content .= "<td><font size=-1><a href=\"$file\">$file</a> $viewfile</font></td>";
$content .= "<td><font size=-1>$filesize</font></td>";
$content .= "<td><font size=-1>$changeddate</font></td></tr>";
}
}
return $content;
}
function diskStats($scriptStats) {
if($scriptStats) {
// $diskTotal = display_size(disk_total_space("/"));
print($content);
}
}
?>
<html>
<head>
Code (php)
</head>
<body>
Code (php)
als ik direct naar het script ga werkt het perfect dus http://domein/php/script.php
de dir word netjes uitgelezen.
maar mijn website maakt gebruik van includes
dus dit
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
// Selecteer de waarde van de GET variabele "pagina"
// index.php?pagina=voorbeeld
switch(strtolower($_GET['action']))
{ /* ALGEMEEN */
// HOME
case "script": $page="/php/script.php";break;
default: $page="php/center.php";break; // default is voor als "pagina" niet gedefinieerd is.
}
// Weergeven van de opgeroepen pagina
include($page);
?>
// Selecteer de waarde van de GET variabele "pagina"
// index.php?pagina=voorbeeld
switch(strtolower($_GET['action']))
{ /* ALGEMEEN */
// HOME
case "script": $page="/php/script.php";break;
default: $page="php/center.php";break; // default is voor als "pagina" niet gedefinieerd is.
}
// Weergeven van de opgeroepen pagina
include($page);
?>
als ik het script nu aanroep krijg ik de melding.
main(): open_basedir restriction in effect. File(/php/script.php) is not within the allowed path(s): (/home/httpd/vhosts/domein/httpdocs:/tmp)
hoe kan ik dit oplossen.
deze vraag staat al om enkele andere forums maar niemand kan me tot nu toe helpen
Ik ben momenteel ook bezig met iets dergelijks (maar dan met PHP op CD i.p.v. op internet)
Weet je zeker dat je wel de juiste rechten hebt ingesteld op de map waarvan je de bestanden probeert uit te lezen.
anders moet je eens zoeken op CHMOD.
dit is alvast eentje die je op weg moet helpen ;-)
http://be2.php.net/manual/nl/function.chmod.php
het werkt trouwens al bij mij via een heel ander script
Een naamgenoot ??
voornaam wel achternaam zal wel niet :)
Code (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
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
<?php
error_reporting(E_ALL);
clearstatcache();
//vars
$host = "http://".$_SERVER["HTTP_HOST"]."/home/".$_SESSION["gebruikersnaam"]."/";
$root = "home/".$_SESSION["gebruikersnaam"]."";
$filename = "script.php";
$dir = (isset($_GET['open'])) ? $root."/".$_GET['open']."/" : $root."/";
$map = (isset($_GET['open'])) ? $_GET['open']."/" : NULL;
$array = array();
//print
//opedir:
$handle=opendir($dir);
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if($file != $filename){
if(is_dir($dir.$file)){
$array['dir'][]= "dir: <a href=\"".$host.$filename."?open=".$file."\">".$file."</a> - created ".date("d-m-Y H:i", filemtime($dir.$file))."<br>";
}
elseif(is_file($dir.$file)){
$array['file'][]= "file: <a href=\"".$host.$map.$file."\" target=\"_blank\">".$file." </a> - ".date("d-m-Y H:i", filemtime($dir.$file))."<br>";
}
}
}
}
closedir($handle);
if(!empty($array['dir'])){
for($i=0;$i<count($array['dir']);$i++){
sort($array['dir']);
echo $array['dir'][$i];
}
}
if(!empty($array['file'])){
for($i=0;$i<count($array['file']);$i++){
sort($array['file']);
echo $array['file'][$i];
}
}
?>
error_reporting(E_ALL);
clearstatcache();
//vars
$host = "http://".$_SERVER["HTTP_HOST"]."/home/".$_SESSION["gebruikersnaam"]."/";
$root = "home/".$_SESSION["gebruikersnaam"]."";
$filename = "script.php";
$dir = (isset($_GET['open'])) ? $root."/".$_GET['open']."/" : $root."/";
$map = (isset($_GET['open'])) ? $_GET['open']."/" : NULL;
$array = array();
//opedir:
$handle=opendir($dir);
while (false!==($file = readdir($handle))) {
if ($file != "." && $file != "..") {
if($file != $filename){
if(is_dir($dir.$file)){
$array['dir'][]= "dir: <a href=\"".$host.$filename."?open=".$file."\">".$file."</a> - created ".date("d-m-Y H:i", filemtime($dir.$file))."<br>";
}
elseif(is_file($dir.$file)){
$array['file'][]= "file: <a href=\"".$host.$map.$file."\" target=\"_blank\">".$file." </a> - ".date("d-m-Y H:i", filemtime($dir.$file))."<br>";
}
}
}
}
closedir($handle);
if(!empty($array['dir'])){
for($i=0;$i<count($array['dir']);$i++){
sort($array['dir']);
echo $array['dir'][$i];
}
}
if(!empty($array['file'])){
for($i=0;$i<count($array['file']);$i++){
sort($array['file']);
echo $array['file'][$i];
}
}
?>