I am using the following code:
Code: Select all
<?php
$base = './'; // current dir
if($dr = opendir($base)){
while (($file = readdir($dr)) !== false) {
if(is_dir($base.$file) && preg_match("/^group1_content/", $file)){
echo "<h2>$file</h2>";
scan_Dir($base.$file);
};
};
closedir($dr);
};
function scan_Dir($dir){
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(! is_dir($dir.$file)) {
echo '<div><p>'.preg_replace("/\.[^\.]*$/", '', $file) // check this line
."</p>\n<code>"
.nl2br(htmlspecialchars(file_get_contents($dir.$file)))
.'</code></div>';
};
};
closedir($dh);
}else
echo 'unable to open directory, check permissions';
}else
echo $dir.' is not seen as a directory';
};
?>
<?php
$dir = "comments/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(! is_dir($dir.$file)) {
$file = preg_replace("/\.[^\.]*$/", '', $file);
echo "<div><p>$file</p>\n<code>"
.nl2br(htmlspecialchars(file_get_contents($dir.$file)))
.'</code></div>';
};
}
closedir($dh);
}else
echo 'unable to open directory, check permissions';
}else
echo $dir.' is not seen as a directory';
?>
<?php
$dir = "comments/";
if (is_dir($dir)) {
if ($dh = opendir($dir)) {
while (($file = readdir($dh)) !== false) {
if(! is_dir($dir.$file)) {
$tmp = pathinfo($dir.$file);
echo "<div><p>{$tmp['filename']}</p>\n<code>"
.nl2br(htmlspecialchars(file_get_contents($dir.$file)))
.'</code></div>';
};
}
closedir($dh);
}else
echo 'unable to open directory, check permissions';
}else
echo $dir.' is not seen as a directory';
?> Removing this line from the code, gets rid of the error message, but the files are print to the screen incorrectly (the filenames are side by side, and the contents of the first file sits next to the second filename on the same line... with the contents of the second file starting below....nl2br(htmlspecialchars(file_get_contents($dir.$file)))
This is just a test phase at the moment - the output can be viewed at: http://www.athenecreations.co.uk/cf/comments.php
Any help would be gratefully received - I am NON-TECHNICAL... so feel free to use plain english (please!)
Thanks
LouPhi