Skip to content

Instantly share code, notes, and snippets.

@tonyjunkes
Last active December 29, 2015 03:29
Show Gist options
  • Save tonyjunkes/7607874 to your computer and use it in GitHub Desktop.
Save tonyjunkes/7607874 to your computer and use it in GitHub Desktop.
CFC for generating JSON data from a folder of images to be used with CKEditor's Image Browser addon.
component name="ImageBrowser"
output="false"
{
remote array function list(required string dir = "")
output="false"
returnformat="JSON"
{
var length = 0;
var path = var image = var folder = "";
var result = [];
arrayEach(
directoryList(expandPath("./#ARGUMENTS.dir#"), true, "path"),
function(x) {
length = listLen(x, "\/");
if (reFind("\w.*\.(jpg|png|gif|bmp)", listGetAt(x, length, "\/"))) {
image = listGetAt(x, length, "\/");
path = reMatch("(#listGetAt(dir, 1, "\/")#).*", reReplace(listDeleteAt(x, length, "\/"), "\\", "/", "ALL"))[1];
folder = listGetAt(x, length - 1, "\/");
arrayAppend(result, {"image": "/#path#/#image#", "folder": "#folder#"});
}
}
);
return result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment