Fork me on GitHub
Please upgrade to 2.1.x here. The 2.0 branch is no longer being updated.
Important security fix: 2.1.10, released 4 May.

File-name based arrays...

edited July 2011 in Vanilla 2.0 Help
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">
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>
<?php }}}?>

Best Answer


Sign In or Register to comment.