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.

Pulling Images from Upload Directories in File Manager

February 10, 2011 6:10pm

Subscribe [3]
  • #1 / Feb 10, 2011 6:10pm

    anonymous162744

    58 posts

    Hello,

    Is it possible to use an upload directory in file manager so that I can pull the images into a gallery, looping through them like a normal exp:channel:entries loop?

  • #2 / Feb 11, 2011 10:40am

    Ingmar

    29245 posts

    Am I understanding you correctly in that you want to get the file names of all images uploaded to a particular directory?

  • #3 / Feb 12, 2011 11:37am

    anonymous162744

    58 posts

    Yes, I want to know if I can pull in all the images from a particular directory.

  • #4 / Feb 13, 2011 2:08pm

    Greg Salt

    3988 posts

    Hi anthonycollini,

    No, that is not possible with the default tags unless you have added all the images to an entry’s custom fields. You would have to develop a simple plugin or use PHP on a template. Because EE is built on top of CodeIgniter it is straightforward to get a list of files in a particular directory (as described in the CodeIgniter Userguide. For example, this code (with PHP on Output) will get all the images from the default avatars directory and store them in an array you can loop through:

    <?php
    $files = get_filenames('/your/server/path/to/webroot/images/avatars/default_set/');
    print_r($files);
    ?>

    Cheers

    Greg

  • #5 / Feb 13, 2011 7:16pm

    anonymous162744

    58 posts

    Thanks Greg!

    Unfortunately that code didn’t work for me because file manager automatically inserts a “_thumbs” directory and your code pulls in the files from that directory. However, looking further based on the input you gave me, I found this which works perfectly. Thank you 😊

    <?php
    
    
    $dir = '/var/www/vhosts/my_domain/httpdocs/images/uploads/{segment_2}/';
    $map = directory_map($dir, TRUE);
    
    foreach($map as $file)
    {
        if( ! @is_dir($dir.$file))
        {
            echo "/images/uploads/{segment_2}/";
        }
    }
    
    ?>
  • #6 / Feb 14, 2011 4:52am

    John Henry Donovan

    12339 posts

    Glad Greg was able to help. Feel free to start a new thread if you have any more questions

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

ExpressionEngine News!

#eecms, #events, #releases