Page 1 of 1
Link all files in a given folder? CMSMS 2.X
Posted: Sun Sep 22, 2019 9:22 pm
by montedavis
Hello,
Is there a module for CMSMS 2.X that works like the old File Listing module? I want to upload files to a directory and view those files on the front end as file name text links.
For example:
file_name_one.html
file_name_two.html
file_name_three.html
Thank you,
Monte
Re: Link all files in a given folder? CMSMS 2.X
Posted: Wed Sep 25, 2019 3:30 pm
by velden
Think it would be a few lines of php code to write a plugin to output an array with file names.
Below some altered code I'm using somewhere to get a list of image files from a specific folder
Code: Select all
$dir = $params['dir'];
$config = cmsms()->GetConfig();
$image_uploads_path = $config['image_uploads_path'];
//look for jpg and png files
$pattern = $image_uploads_path . DIRECTORY_SEPARATOR . trim($dir,DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . '*.{jpg,png}';
$images = glob($pattern,GLOB_BRACE);
foreach ($images as $image) {
$basename = basename($image);
echo $basename;
}
$image_folder_url = $config['uploads_url'] . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR . trim($dir,DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
In this case the code is used in a UDT which is called with the 'dir' parameter, but if your folder is constant you can hardcode it in the UDT.
The code above doesn't make much sense on its own but may be a starting point for your own UDT/plugin.
Re: Link all files in a given folder? CMSMS 2.X
Posted: Wed Sep 25, 2019 5:25 pm
by DIGI3
CGExtensions and CGSimpleSmarty both have tags that will build a file list from a directory. You can then use that array to do what you need to do in Smarty.
For example, here's how I've used it in LISE to build a lightbox gallery from all of the images in a folder:
Code: Select all
{if $item->fielddefs.image->value}
{$path="images/artists/{$item->fielddefs.image->value|dirname}"}
{$files=cgsimple::get_file_listing($path,'thumb_')}
{foreach $files as $file}
<a class="featured-image" href="{uploads_url}/{$path}/{$file}" data-lightbox="featured">
{CGSmartImage src1="{uploads_url}" src2=$path src3=$file noembed=1 filter_croptofit='75,75,c,1'}
<div class="overlay text-right"><i class="fas fa-search-plus"></i></div>
</a>
{/foreach}
{/if}
Re: Link all files in a given folder? CMSMS 2.X
Posted: Wed Sep 25, 2019 8:07 pm
by magallo
maybe this will work too:
{assign var='files' value='uploads/album/*.html'|glob}
{foreach from=$files item='file'}
.....
{/foreach]
Re: Link all files in a given folder? CMSMS 2.X
Posted: Wed Oct 02, 2019 2:20 pm
by montedavis
Thank you all for your help. I will give these suggestions a try!