Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/91032-multidimensional-filetree-array/
Share on other sites

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.