Closed Thread Icon

Preserved Topic: PHP file tree from nested arrays? (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12740" title="Pages that link to Preserved Topic: PHP file tree from nested arrays? (Page 1 of 1)" rel="nofollow" >Preserved Topic: PHP file tree from nested arrays? <span class="small">(Page 1 of 1)</span>\

 
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-14-2003 20:29

Hey guys,

How would I go about creating a 'file tree menu' from a PHP nested array? I have seen many good javascript ones but I'm not sure how to get the data from a nested array to a tree.

Ideally the whole thing would done in php if possible. My only main issue is that the file tree must have it's links available to search engine spiders, it's no good them being written in javascript because web bots don't use javascript.

what can I do?

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-18-2003 03:14

http://www.phpguru.org/treemenu.php

there is also a tree php class on the same website - i don't have a clue what these things are but they look like what I need, would any of you lovely talented and brilliant minded individuals be able to put my website file list script together with this treemenu to create what i'm after?

pretty please?

if somebody is willing my file list script is a follows:<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre><pre><?php

$root_path = ".";

function parseDir($path)
{
if (!($dir_handler = opendir($path))) {
die("Can't opendir() path '". $path ."'");
}

$files = array();

while (($file = readdir($dir_handler)) !== false) {
$temp_path = realpath($path."/".$file);
if ($file != "." && $file != "..") {
if (is_dir($temp_path)) {
$files = array_merge($files, parseDir($temp_path));
} elseif (is_file($temp_path)) {
$pathInfo = pathinfo($temp_path);
if (preg_match("/(html?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-18-2003 23:15

ok... heres a quick and dirty recursive script... take what you can, leave what you must or so

code:
<?php

function parseDir($path)
{
if ($path{strlen($path) -1} != '/')
$path .= '/';
$dir_handler = opendir($path);
$files = array();
while ($aFile = readdir($dir_handler))
{
if (($aFile == '.') &#0124; &#0124; ($aFile == '..'))
continue;
elseif (is_dir($path. $file))
{
$files[] = array($path. $file, parseDir($path. $file. '/'));
}
else
$files[] = $path. $file;
}
}


function printNestedArray($array,$indention = 0)
{
foreach ($array as $anSubArray)
{
if (is_array($anSubArray))
{
print $indention * ' '; //not sure this works... there is a fucntion for it. look it up. str_repeat or so.
print 'folder: '. $anSubArray[0]. '<br>';
printNestedArray($anSubArray[1],$indention + 1);
}
else
{
print 'file: '. $anSubArray. '<br>';
}
}
}


?>




sorry for the messy indetion, I'm tired.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-19-2003 01:26

is there a way to copy and paste code from this forum without it ending up as one huge line?


visit my CryoKinesis Online Gallery

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 05-19-2003 13:36

if your browser sucks that much, I don't think so, currently.
you could take the html-source and replace all <br>s with newlines, though.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 05-19-2003 20:22

actually it seems to be a problem with ie only - i copied the code using mozilla and it retained the formatting.

but it throws a parse error on line 11, i can't see any obvious lack of or bad usage of ; but then I'm a complete n00b so it's more than likely I missed something.

quisja
Paranoid (IV) Inmate

From: everywhere
Insane since: Jun 2002

posted posted 05-19-2003 22:43

The one massive line thing is usually a notepad issue (if that's what you're using). Better text editors (like text pad, or other in the faq) interpret more variations of line breaks.

« BackwardsOnwards »

Show Forum Drop Down Menu