I want to make a image gallery (for this there are some free and paid version available) but to show them as per Month wise there is no such free extension.

  • mainfolder
    • May
      • someimage.jpg
      • someimage.jpg
    • June
      • ...

So i thought to create folder having name as month then fetch all images under them and using some jquery i can make a gallery.

I created the above idea on localhost in PHP but in magento i am new , no idea from where to start.

In some_custom.phtml

$mypath3 = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK).'media/mediamadd/';
$dirpass = scandir($mypath3);  
print_r($dirpass);  // this gives nothing

Kindly suggest.


Just as starting point ... you can get all images from your folders in this way:


// adjust this to your folder
$root = './mainfolder/' . date('n');
$iterator  = new RecursiveIteratorIterator(
    new RecursiveDirectoryIterator($root, RecursiveDirectoryIterator::SKIP_DOTS),

foreach ($iterator as $path => $item) {
    if ($item->isFile() && $item->getExtension() == 'jpg') {
        // your logic here for $path

Folder structure would be

  • mainfolder
    • 1
    • ...
    • 12

Example is for standalone usage, but you can use this code in your modules block class.

  • can you plz tell me how to pass http://websitename.com/media/mediamadd/ in place of $root in RecursiveDirectoryIterator – inrsaurabh Jun 21 '17 at 11:48
  • as i got this error RecursiveDirectoryIterator::__construct(http://websitename.com/media/mediamadd/): failed to open dir: not implemented – inrsaurabh Jun 21 '17 at 11:54
  • Try to remove domain name ... just use ./media/mediamadd/ . date('n') . For date('n') you have to create subfolders 1-12. – sv3n Jun 21 '17 at 12:04
  • $root = 'media/mediamadd/'; this path works. – inrsaurabh Jun 21 '17 at 12:52
  • what is date('n') is n=1 means folder having name 1 and n=2 means folder having name 2 – inrsaurabh Jun 21 '17 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.