Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Try Vanilla Forums Cloud product

In this Discussion

Ready to contribute?

Amazing! Sign our contributors' agreement and then join us on GitHub.

Update for critical security issue in PHPMailer included in release Vanilla 2.3.1
Please upgrade to 2.3 here. The 2.2 and earlier branches are no longer being updated.

File-name based arrays...

edited July 2011 in Vanilla 2.0 - 2.2
OK, so I am back on the Vanilla project, only this time on a professional level.

I am using Vanilla as a base for my employer's website. I am creating a photo gallery application based on the Addon application used here on the site. So far so good, though I have run into a snag on something that I have not seen done in vanilla as of yet.

I want to build a model that will allow for indexing of photos already in a certain directory, based on the contents of the file name.

I am using the pages plugin for direct results of my experiments. I have figured out how to display the photos in a certain directory, though I am having trouble breaking down the array of file names into a sub array for each file.

Here is what I have so far...

I'm probably making a newbie mistake, though I can't seem to figure it out.

Any suggestions would be much appreciated. Thanks.

$ClassDir = PATH_ROOT.'/themes/MyTheme/design/images/namedfiles2009'; $PublicDir = '/website/themes/MyTheme/design/images/namedfiles2009'; /////////////////// function GetFilesInfo($Directory) { $Files = scandir($Directory); foreach ($Files as $FileName) { $Item['FileName'] = $FileName; $Item['Class'] = (substr($FileName, 0, 3)); $Item['ID'] = (substr($FileName, 3, 3)); $Item['Size'] = (substr($FileName, 6, 1)); if (strlen($FileName) > 11) { if (substr($FileName, 7, 1) != 'F') { $Item['Name'] = (substr($FileName, 9)); $Item['Frame'] = 0; } else { $Item['Name'] = (substr($FileName, 10)); $Item['Frame'] = 1; } } else { $Item['Name'] = NULL; $Item['Frame'] = 0; } $AllFiles[] = $Item; } return $AllFiles; } /////////////////// <div id="Custom"> <ul class="Gallery"> <?php GetFilesInfo($ClassDir); foreach($AllFiles as $Item){ if (substr($Item['FileName'], 0, 1) != '.') { if (substr($Item['FileName'], 6, 1) != 'L') { ?><li class ="Item Gallery Image"> <a href="<?php if ($Item['Name'] != NULL) { echo '/website/gallery/item' . DS . $Item['Name']; } else { echo '/website/gallery/item' . DS . $Item['FileName']; } ?>"> <img src="<?php echo $PublicDir . DS . $Item['FileName']; ?>" Class="Gallery Image"></img></a></li> </ul> <?php }}}?> </div>

Best Answer


Sign In or Register to comment.