Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod
- » MetaMod General Support
- » Request for php recipe
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?
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!
- Index
- » MetaMod
- » MetaMod General Support
- » Request for php recipe
Board Info
- Board Stats:
- Total Topics:
- 1699
- Total Polls:
- 6
- Total Posts:
- 5967
- Total Posts Today:
- 2
- User Info:
- Total Users:
- 8028
- Newest User:
- musial8334
- Members Online:
- 0
- Guests Online:
- 121
- 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