Hey all.
I got one of those cases where i didn’t expect to be stumped at all. Seemed like a slam dunk, but guess again.
I’m trying to read contents of a folder with images in it and create a list of links to those images. I thought the the @DIRECTORY binding would be perfect for this.
So i created a TV named ’pictures’ of type text area, in the values field i entered @DIRECTORY hcweb/htdocs/assets/images/properties/457815/. This is my test box so the server root contains multiple projects. hcweb is one of them.
Then i simply added the [*pictures*] to the template and opened a page in the backend and expected to see the names of the files in that directory in the tv field, but it was empty. I tried moving the binding call to the "Default Value" field but instead of resolving the binding it just displayed the call.
So either i really don’t understand what @DIRECTORY is supposed to do or something is not working right here.
Has anyone seen this or have an idea of what is going on?
Thanks.
I think @DIRECTORY is meant only to be used in the Input Option Values field.
Even if it worked, it would include the . and .. directories which you probably don’t want and there would be no way to make individual links out of the items.
A simple snippet using readdir() is probably the way to go (something like this):
<?php
//Open images directory
$path ='images'; // change to actual path
$dir = opendir($path);
$output = "";
//List files in images directory
while (false !== ($file = readdir($$dir))) {
if ($file != '.' && $file != '..') {
$output .= '<a href="' . $path . $file . '">' . $file . '</a><br />';
}
}
closedir($dir);
return $output;
?>