ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Attempt to show directory file list for a folder based upon member name

September 04, 2008 8:14am

Subscribe [3]
  • #1 / Sep 04, 2008 8:14am

    judin

    54 posts

    Hello

    This is not an ExpressionEngine question per se, but will be using EE for the rest of the page and to interact…

    I’m putting together a section on our website for our clients to download files we’ve created for them once finished (a bit like a simple version of Basecamp by 37 Signals). I’ve got everything setup, including the area for my colleagues to upload the files, but need to achieve the following.

    The client will log in and be shown a page, with their logo, how to contact us, links to resources, and - the clever bit - their files to download, with links automagically created from a file listing of a particular folder.

    I wish to display a directory listing for a specific folder. If the clients name is Smashing Corp, I will create a user called ‘smashing’ and upload their files into /clientfiles/smashing/. I would like a file listing to be shown, based upon ‘smashing’ as the folder, showing all of the files in this space (no folders, just files). I’m a bit stuck as to what to use to display the listing!

    Any ideas? I’ve looked at ‘Relay’, and AJAX based file manager but cannot get it to install properly. Now I’m just stuck!

  • #2 / Sep 04, 2008 8:48am

    Mark Bowen

    12637 posts

    Hiya,

    Could you not just have the files stored in a weblog (perhaps one entry per file or use the File extension for multiple related files) and then simply have a drop-down menu to choose the name of the person that you want the file to be viewed by. You could then use the :

    search://field_name=”“

    parameter to query the weblog to only bring back items for their name?

    Would that work. Probably a lot easier than trying to get another system working alongside ExpressionEngine I would have thought. There are other ways you could do this in ExpressionEngine and depending on how secure you want it to be then other items could be added in to the workflow but I think personally this would be the easiest way.

    Hope that helps.

    Best wishes,

    Mark

  • #3 / Sep 04, 2008 9:52am

    judin

    54 posts

    The benefit of doing it my way would be that you could add or change files directly by FTP to the appropriate folder and the file listing would be immediately updated, without having to Edit the EE entry, find the appropriate file URL and update that also.

    I’m trying to think of a better way to explain this, so I’ve uploaded a picture… does this help explain!? And apologies, but this was done in PowerPoint quickly at work, hence picture quality!

    Thanks,
    Justin

  • #4 / Sep 04, 2008 11:50am

    judin

    54 posts

    Ok, got this almost working 100% using this code:

    <?php
    $files = array();
    $dir = opendir('/home/hsphere/local/home/microdom/domain.com/downloads/lillypad/url_title/');
    while(($file = readdir($dir)) !== false)
    {
      if($file !== '.' && $file !== '..' && !is_dir($file))
      {
        $files[] = $file;
      }
    }
    closedir($dir);
    sort($files);
    for($i=0; $i<count($files); $i++)
    {
      echo "<li><a >$files[$i]</a></li>";
    }
    ?>

    Just trying to work out how to get the {url_title} bit working at the top of the script. Any ideas would be great, otherwise I’m trialling and erroring!

  • #5 / Sep 04, 2008 11:59am

    Mark Bowen

    12637 posts

    Hiya,

    Is this code running from within an ExpressionEngine template. If so then would this work at all?

    $dir = opendir('/home/hsphere/local/home/microdom/leapfrogresearch.co.uk/downloads/lillypad/'.'{url_title}'. '/');

    Best wishes,

    Mark

  • #6 / Sep 04, 2008 12:08pm

    judin

    54 posts

    Thanks, Mark.

    It is running within an EE template, but that doesn’t work - although it does load the page, just not the content. If I type the url_title stuff in manually, it works of course.

    And yes, it is within EE weblog entry code, as I have a hyperlink to open the file further down the script working fine. Will try playing on!

    Justin

  • #7 / Sep 04, 2008 12:13pm

    judin

    54 posts

    Here’s my code so far, with Mark’s suggestion $dir line. I’m thinking I might need to change the {url_title} into a PHP variable, but again haven’t got that working correct yet! (Looking at http://ellislab.com/forums/viewthread/84201/ and http://ellislab.com/forums/viewthread/82079/

    <?php
    $files = array();
    $dir = opendir('/home/hsphere/local/home/microdom/domain.co.uk/downloads/clients/'.'{url_title}'. '/');
    while(($file = readdir($dir)) !== false)
    {
      if($file !== '.' && $file !== '..' && !is_dir($file))
      {
        $files[] = $file;
      }
    }
    closedir($dir);
    sort($files);
    
    for($i=0; $i<count($files); $i++)
    {
      echo "<li><a >$files[$i]</a></li>";
    }
    ?>
  • #8 / Sep 04, 2008 12:16pm

    Mark Bowen

    12637 posts

    Hmm,

    If you echo out this :

    echo "{url_title}";

    at the top of your PHP code then what does it give you?

    Also I meant to mention that for this to work you would need for that PHP code to be within the weblog entry tag for this to work unless you snatch the url_title from the segment in the URL of the browser instead? Bear in mind though that if you do use a segment variable that anyone could possibly guess the name of your client and thus get access to their files.

    $dir = opendir('/home/hsphere/local/home/microdom/leapfrogresearch.co.uk/downloads/lillypad/'.'{segment_3}'. '/');

    Don’t know what segment you are using but hopefully that should work too. You may also need to adjust your PHP parsing settings depending upon which of these two methods you go for of course.

    Hope that helps.

    Best wishes,

    Mark

  • #9 / Sep 04, 2008 12:26pm

    judin

    54 posts

    I think fantastic (segment_2)!

    I’m using EE for login/password access to see the files, and we’re switching off Directory Listing in htaccess.

    Not the most secure method, but it’ll definitely do for this month-long trial.

    Mark, you’re my hero, and I wish to thank you so very much for your time. Hopefully this thread will help someone else achieve a similar effort in the future.

    Kindest regards,
    Justin

  • #10 / Sep 04, 2008 12:30pm

    Mark Bowen

    12637 posts

    Mark, you’re my hero, and I wish to thank you so very much for your time. Hopefully this thread will help someone else achieve a similar effort in the future.

    Kindest regards,
    Justin

    Hi Justin,

    No problem at all. Thanks for the very kind words!! 😊

    Glad it’s all working for you now.

    Hope it all goes well for you.

    Best wishes,

    Mark

  • #11 / Nov 23, 2009 2:52pm

    onepanman

    44 posts

    Hey judin and Mark,

    I am attempting to do the same thingas Judin. I need to do a directory listing within a template using EE security. I followed the above info and have the listing working fine; however, I need the items to be hyperlinkable so that the user can download the files.  You mentioned at you have it doing so further down, can you provide that code?  I am using it just a template (not a weblog) since there is only one folder they need access too (so no URL_TITLE variable was needed).

    Thanks,

  • #12 / Nov 23, 2009 3:01pm

    onepanman

    44 posts

    nevermind. just figured that out. thanks guys. this was what I needed.

  • #13 / Nov 23, 2009 3:18pm

    judin

    54 posts

    Glad you sorted. Was just digging out my sample code…

    <h2>Project files</h2>
    <p>To download a file to your computer, right-click and choose 'Save target as…' or 'Download file', depending on your browser.<br />
    <ul id="files"><br />
    <?php<br />
    $files = array();<br />
    $dir = opendir('/home/domains/examplesite.co.uk/downloads/projectareafiles/'.'{segment_3}'. '/');<br />
    while(($file = readdir($dir)) !== false)<br />
    {<br />
      if($file !== '.' && $file !== '..' && !is_dir($file))<br />
      {<br />
        $files[] = $file;<br />
      }<br />
    }<br />
    closedir($dir);<br />
    sort($files);</p>
    
    <p>for($i=0; $i<count($files); $i++)<br />
    {<br />
      echo "<li><a >$files[$i]</a></li>";<br />
    }<br />
    ?><br />
    </ul>

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases