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?
This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.
The active forums are here.
February 10, 2011 6:10pm
Subscribe [3]#1 / Feb 10, 2011 6:10pm
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
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
Yes, I want to know if I can pull in all the images from a particular directory.
#4 / Feb 13, 2011 2:08pm
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
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
Glad Greg was able to help. Feel free to start a new thread if you have any more questions