开发者

Is there a way to return a list of all the image file names in a folder using only Javascript?

I have a dropbox account. I put a bunch of images in a public folder. I'd like to display the images using shadowbox.

Right now, I'm manually entering the filenames into this html file. Is there a way to dynamically update the gallery when I drag new images into the images folder?

I'd prefer javascript if it's possible. If it's not possible with javascript, any other suggestions to use shadowbox to automatically show a gallery of images stored on dropbo开发者_运维问答x?

I know dropbox has their own gallery feature, but I'd like to use my own that's unbranded. Thanks for any help!


Bad News First...

Javascript cannot read remote directories on the server, for security reasons. You'll have to use a server-side language instead.

Good News Last...

There appears to be a PHP Script that can access your dropbox account, and return the filenames to Javascript: http://forums.dropbox.com/topic.php?id=15660 - a demo can be viewed online at http://2boandco.com/demo-php-dropbox-gallery


The only think you could possibly do is name the files contiguously (1.jpg, 2.jpg), get the HEAD of them one by one, and then stop when you get a 404.


I ended up creating a python script that outputs the html I need to work with Shadowbox.

I just need to have a folder called "shadowbox" with the shadowbox files in it, a folder called "Full" with the actual images, and a folder called "Thumbs" with thumbnails that have the same name as the full image. Then the script will automatically create a file called "gallery.html".

Here's a sample.. http://dl.dropbox.com/u/154234/Images/gallery.html

Here's the python script for anyone interested in using it. I'm just a novice programmer, so any suggestions on how to make the code more elegant would be appreciated. Thanks!

http://dl.dropbox.com/u/154234/Images/update.py


Whenever a new image (or any other files as a matter of fact) is added to some dropbox folder (on the client side, within the OS), have a background script that would update a content.json file structure such as:

[
  "foo.jpg", "bar.jpg"
]

Using file system change notification hooks such as FSEvents, inotify, etc.

And then within your web app, perform some ajax call on the content.json located within your dropbox, and simply iterate the json array to get the file names.

Benefits:

  • No need for any server side script (host on any vanilla static host)
  • content.json can be generated from any of your dropbox without the need to redeploy your web app/html page.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜