Static Image Location

Permalink
Hi Guys,

I've got a HTML theme that loads a random background image every time you load a page. These images are loaded from a designated folder of images. Let's say it's 'theme/bg-images'.

I can change the path of the folder where the images are to be located. However all the images need to reside in that folder.

My question is: Is it possible to have my client load and manage the images in via concrete and still retain all the images in a single folder?

 
hutman replied on at Permalink Reply
hutman
Rather than doing it in a folder within your structure you could have them manage images within a fileset. Then in your script you would just get all the files from that fileset and randomly show one. Here is some sample code

$fs = FileSet::getByName("FILESET NAME");
$fileList = new FileList();
$fileList->filterBySet($fs);
$fileList->filterByType(FileType::T_IMAGE);
$files = $fileList->get();
$size = sizeof($files);
$random = rand(0,$size - 1); //array starts at zero, otherwise you never will get your first image in your set or maybe your last?
$fAtt = $files[$random];
$img_src = $fAtt->getRelativePath();
frankiestyles replied on at Permalink Reply
Hi hutman,

Thanks very much for your reply.

Is this code suitable for 5.7? I can't find most of these methods in the API. Although i do understand the general gist of your code.

Would you know the equivalent 5.7 methods?
frankiestyles replied on at Permalink Reply
Actually apologies hutman - your code was spot on.

It didn't like this though:

$fileList->filterByType(FileType::T_IMAGE);

gets me:

Class 'FileType' not found

It would be great if i could filter by image type 'jpg'.
hutman replied on at Permalink Reply
hutman
Sorry about that, as you said there are no 5.7 docs to speak of so it's really hard to tell what will/won't work other than just guess and check. All that line does is make sure it only grabs images, but as long as you train your client to only put images in that set you should be fine.
frankiestyles replied on at Permalink Reply
Thanks hutman, you've been a great help :)