Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

Request for php recipe

Request for php recipe

Hi, can MetaMod display the latest image from a directory? For example, I create a folder in the images folder called "month". I upload a new image into that directory each month. MetaMod sees that there is a new image and will display it until I upload another image.

Is this possible?

cork
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Re: Request for php recipe

Hi Cork,

generally, MetaMod is all about deciding which other module to display, then telling Joomla to display that module. However, there are various features that can be used to generate the contents of a module without actually pulling in a pre-made module from the module manager.

So, my first recommendation would be to look in the Joomla Extensions directory for a module that can display the most recent image in a folder, and forget MetaMod.

If you can't find anything, then you could use some code like this inside MetaMod:

$path = "/path/to/images/myfolder";
$latest_ctime = 0;
$latest_filename = '';   

$d = dir($path);
while (false !== ($entry = $d->read())) {
  $filepath = "{$path}/{$entry}";
  // could do also other checks than just checking whether the entry is a file
  if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
      $latest_ctime = filectime($filepath);
      $latest_filename = $entry;
    }
  }
}

// now $latest_filename contains the filename of the newest file

if ($latest_filename != "") {
  echo '<img src="/images/myfolder/' . $latest_filename . '" />';
}


Hope that helps,
Stephen

p.s. this is untested but is probably very close to being right!

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3313 Posts
User info in posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1667
Total Polls:
6
Total Posts:
5910
Total Posts Today:
1
User Info:
 
Total Users:
10152
Newest User:
kasautiizindagiikay
Members Online:
0
Guests Online:
203

Online: 
There are no members online

Forum Legend:

 Topic
 New
 Locked
 Sticky
 Active
 New/Active
 New/Locked
 New Sticky
 Locked/Active
 Active/Sticky
 Sticky/Locked
 Sticky/Active/Locked