unable to access image folder

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
Sendlingur
Forum Members
Forum Members
Posts: 60
Joined: Wed Aug 08, 2018 4:59 pm

unable to access image folder

Post by Sendlingur »

I'm trying to display images from this folder
uploads/images/mypicfolder
to do that I'm using this snippet, which I got from https://cmscanbesimple.org/blog/list-images :

Code: Select all

$url = isset($params['/uploads/images/ ']) ? $params['/uploads/images/ '] : '';
$dir = cmsms()->config['root_path'] . DIRECTORY_SEPARATOR . $url;

echo "<ul>\n";
if (is_dir($dir))
{
  if ($dh = opendir($dir))
  {
    while (($file = readdir($dh)) !== false)
    {
      if ( ('file' == filetype($dir . $file)) && (substr($file,0,6) != 'thumb_') )
      {
        echo '<li><a href="'.$url.$file.'" class="fancybox"><img src="'.$url.'thumb_'.$file.'" alt="'.$file.'" /></a>'."</li>\n";      
      }
    }
    closedir($dh);
  }
}
echo "</ul>\n";
I have a custom field for the name of the folder since the user should be able to add different names of folders for each article. (im using the News module)

The custom field is called picfolder.

So in my news detail template I have this tag

{list_images url='{$entry->picfolder}'}

The problem is that I always get a list of some files on the root. but not the image files I want to display.

what am I doing wrong here?
Jos
Support Guru
Support Guru
Posts: 4016
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: unable to access image folder

Post by Jos »

$params['/uploads/images/ '] is not a correct modification of the original code
Sendlingur
Forum Members
Forum Members
Posts: 60
Joined: Wed Aug 08, 2018 4:59 pm

Re: unable to access image folder

Post by Sendlingur »

I'm aware of that, I've tried all kinds of paths but with out any luck.
Could you please guide me on what would be the correct modification to access the image folder?
Jos
Support Guru
Support Guru
Posts: 4016
Joined: Wed Sep 05, 2007 8:03 pm
Location: The Netherlands

Re: unable to access image folder

Post by Jos »

Try this:

Code: Select all

$url = isset($params['url']) ? $params['url'] : '';
$dir = cms_join_path(cmsms()->config['image_uploads_path'], $url);

echo "<ul>\n";
if (is_dir($dir))
{
  if ($dh = opendir($dir))
  {
    while (($file = readdir($dh)) !== false)
    {
      if ( ('file' == filetype($dir . $file)) && (substr($file,0,6) != 'thumb_') )
      {
        echo '<li><a href="'.$url.$file.'" class="fancybox"><img src="'.$url.'thumb_'.$file.'" alt="'.$file.'" /></a>'."</li>\n";      
      }
    }
    closedir($dh);
  }
}
echo "</ul>\n";
And use tag: {list_images url=$entry->picfolder}
Sendlingur
Forum Members
Forum Members
Posts: 60
Joined: Wed Aug 08, 2018 4:59 pm

Re: unable to access image folder

Post by Sendlingur »

Thanks Jos for your help
This works but I ended up using another solution which gives the same result.
Locked

Return to “CMSMS Core”