Link all files in a given folder? CMSMS 2.X

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Post Reply
montedavis
Forum Members
Forum Members
Posts: 64
Joined: Wed Jul 03, 2013 7:44 pm

Link all files in a given folder? CMSMS 2.X

Post 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
User avatar
velden
Dev Team Member
Dev Team Member
Posts: 3483
Joined: Mon Nov 28, 2011 9:29 am
Location: The Netherlands

Re: Link all files in a given folder? CMSMS 2.X

Post 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.
User avatar
DIGI3
Dev Team Member
Dev Team Member
Posts: 1628
Joined: Wed Feb 25, 2009 4:25 am
Location: Victoria, BC

Re: Link all files in a given folder? CMSMS 2.X

Post 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}
Not getting the answer you need? CMSMS support options
User avatar
magallo
Dev Team Member
Dev Team Member
Posts: 109
Joined: Thu Mar 24, 2011 12:37 am

Re: Link all files in a given folder? CMSMS 2.X

Post by magallo »

maybe this will work too:
{assign var='files' value='uploads/album/*.html'|glob}
{foreach from=$files item='file'}
.....
{/foreach]
montedavis
Forum Members
Forum Members
Posts: 64
Joined: Wed Jul 03, 2013 7:44 pm

Re: Link all files in a given folder? CMSMS 2.X

Post by montedavis »

Thank you all for your help. I will give these suggestions a try!
Post Reply

Return to “Modules/Add-Ons”