How I Created AWS S3 Hierarchical File System Using PHP

Story cut short, I got a project to pull files from Amazon S3 and allow users to navigate into sub-directories knowing S3 is a Flat file system.

I wrote some PHP functions to take the folders and make them array keys of an multidimensional array. The plan was the put the files into the arrays using the directory as key but I couldn’t figure that out yet.

Well, I got that part done with PHP then sent to JavaScript through AJAX request. Iterated through the objects and was able create a hierarchical unordered listing using jQuery.

The whole codes can be found on GitHub Gist. I might be able to expand this in the future, but for now it might be messy but helps 🙂

You can send the data-prefix attribute value back to PHP to get back files in that prefix. Use the comment on the GitHub gist page or here if you have further issues, I went beyond to pull the files related to prefixes but the codes are messy 😀