Hi,
Can someone please help me out for the sorting problem for this php script? Because there is no an ability for sorting directories or files?
Any responses will be greatly appreciated it.
$path = "docs/";
function createDir($path = '.')
{
if ($handle = opendir($path))
{
echo "<ul>";
while (false !== ($file = readdir($handle)))
{
if (is_dir($path.$file) && $file != '.' && $file !='..')
printSubDir($file, $path, $queue);
else if ($file != '.' && $file !='..')
$queue[] = $file;
}
printQueue($queue, $path);
echo "</ul>";
}
}
function printQueue($queue, $path)
{
foreach ($queue as $file)
{
printFile($file, $path);
}
}
function printFile($file, $path)
{
echo "<li><a href=\\"".$path.$file."\\" target=\\"_blank \\">$file</a></li><br><br>";
}
function printSubDir($dir, $path)
{
echo "<li><span class=\\"toggle\\">$dir</span>";
createDir($path.$dir."/");
echo "</li>";
}
createDir($path);
[FPHP]scandir[/FPHP] sorts.
I am sorry didn’t tell you guys what kind of sorting I was looking for.
If there is not too much to ask I’d like the alphebetical by ascendant or descendant.
Thanks so much for your help.
The links that we gave should push you in the right direction. Try those and let us know how you get on.
Sorry. I have tried, it didn’t work.
$path = "docs/";
function createDir($path = '.')
{
if ($handle = opendir($path))
{
echo "<ul>";
while (false !== ($file = readdir($handle)))
{
if (is_dir($path.$file) && $file != '.' && $file !='..')
printSubDir($file, $path, $queue);
else if ($file != '.' && $file !='..')
$queue[] = $file;
}
printQueue($queue, $path);
echo "</ul>";
}
}
function printQueue($queue, $path)
{
foreach ($queue as $file)
{
printFile($file, $path);
}
}
function printFile($file, $path)
{
echo "<li><a href=\\"".$path.$file."\\" target=\\"_blank \\">$file</a></li><br><br>";
}
function printSubDir($dir, $path)
{
echo "<li><span class=\\"toggle\\">$dir</span>";
createDir($path.$dir."/");
echo "</li>";
}
uksort($array, 'strcasecmp');
createDir($path);