Forum Moderators: coopster
Directory A
Content 1
Content 2
etc
Directory B
Content 1
Content 2
etc
Im trying to set up where i can add directory names & contents into a MySQL database
<?php
if ($handle = opendir('/var/www/html/project/')) {
while (false!== ($file = readdir($handle))) {
if ($file!= "." && $file!= "..") {
echo "$file\n <br>";
}
}
closedir($handle);
}
?>
Thanx Everyone
<?php
function display($dir) {
$html = '';
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(is_dir($f)) {
$ds = $dir.$f."/";
$innerstuff = display($ds);
$html .= $innerstuff;
}else{
$html .= "<tr><td>".$dir.$f."</td><td>".filesize($dir.$f)."</td></tr>\n";
}
}
}
return $html;
}
echo "<table width=80% cols=2>\n";
$stuff = display("./");
echo $stuff;
echo "</table>\n";
?>
folder a
photoa.jpg
photo2.jpg
folder b
myphoto1.jpg
myphoto2.jpg
I have had a go at trying to get the following to work but it will only list the folders in the directory
<?php
if ($handle = opendir('/var/www/html/project/photos')) {
while (false!== ($file = readdir($handle))) {
if ($file!= "." && $file!= "..") {
echo "$file <br>";
}
}
$dir = "$file";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file2 = readdir($dh))!== false) {
echo "filename: $file2 : filetype: " . filetype($dir . $file2) . "\n";
}
closedir($dh);
}
closedir($handle);
}
}
?>
what about this
<?php
function display($dir) {
$html = '';
$d = dir($dir);
while ($f = $d->read()) {
if(($f!= ".") && ($f!= "..")) {
if(is_dir($f)) {
$ds = $dir.$f."/";
$innerstuff = '<tr><td> </td></tr><tr><td><b>' . $ds . '</b></td></tr>' . display($ds);
$html .= $innerstuff;
}else{
$html .= "<tr><td>".$f."</td></tr>\n";
}
}
}
return $html;
}
echo "<table width=80% cols=2>\n";
$stuff = display("./");
echo $stuff;
echo "</table>\n";
?>