HaLo2FrEeEk Posted February 14, 2008 Share Posted February 14, 2008 I need to make a function that will build a multi-dimensional array of a filetree, starting in a directory I set (prefferably through POST or REQUEST variables). I have a lot of files uploaded that I need to make links to and I would very much prefer not to have to write them all out. I also want some sort of functionality to display a picture that goes along with the file (it will be named the same), but not show up in the filetree. The uploaded files are movies and the pictures are to be thumbnails. Also, if possible, it would be nice to also upload a text file with the same name as the movie and thumbnail and have it contain a description of the movie. Is this possible? I was never good at recursive arrays, it was always my downfall in Java. Quote Link to comment https://forums.phpfreaks.com/topic/91032-multidimensional-filetree-array/ Share on other sites More sharing options...
sasa Posted February 14, 2008 Share Posted February 14, 2008 Is this possible?yes, just start and ask if you got trouble Quote Link to comment https://forums.phpfreaks.com/topic/91032-multidimensional-filetree-array/#findComment-466602 Share on other sites More sharing options...
HaLo2FrEeEk Posted February 14, 2008 Author Share Posted February 14, 2008 I've already started, but I said I sucked at recursive functions, I always have for some reason. I've got something, but it isn't an array. It works, so I might stick with it, but I think array's would be better, easier to sort (I can do it by name, which is what I want, for some reason the script I have now doesn't sort by name.) Can you take a look at this script and let me know what I have to do to make it make an array: <?php function getList($c = '.', $wcwd = false) { if($wcwd === false) $wcwd = substr($wcwd = $_SERVER['REQUEST_URI'], 0, strrpos($wcwd, '/') + 1); $d = opendir($c); while($f = readdir($d)) { $type = substr(strtolower($f), strrpos($f, ".")+1, strlen($f)); if($f != "index.php" && $type != "png") { if(strpos($f, '.') === 0) continue; $ff = $c . "/" . $f; $fi = substr($ff, 0, strrpos($ff, ".")); $isfile = (filetype($ff) == file) ? "<img src=\"".$fi.".png\" alt=\"\">" : ""; echo $isfile."<a href=\"" . $wcwd . $ff . "\">" . $f . "</a><br>\n"; if(is_dir($ff)) getList($ff, $wcwd); } } } ?> <?php getList(); ?> I've already implemented the option to show a picture thumbnail for each movie, I haven't tried to do the text file description, that'll come later when I have everything formatted. I just want to be able to sort the array by name and echo it formatted. Quote Link to comment https://forums.phpfreaks.com/topic/91032-multidimensional-filetree-array/#findComment-466639 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.