Pull and Display Images in Website Gallery from Dropbox Directory

不羁岁月 提交于 2019-12-05 14:59:39

It's really pretty simple. Here is a snippet from http://davidwalsh.name/generate-photo-gallery Follow this link and you'll found a simple way to solve your issue (demo included).

/** settings **/
$images_dir = '<path-to-your-dropbox>';
$thumbs_dir = '<path-to-your-generated thumbnails>';
$thumbs_width = 200;
$images_per_row = 3;

/** generate photo gallery **/
$image_files = get_files($images_dir);
if(count($image_files)) {
  $index = 0;
  foreach($image_files as $index=>$file) {
    $index++;
    $thumbnail_image = $thumbs_dir.$file;
    if(!file_exists($thumbnail_image)) {
      $extension = get_file_extension($thumbnail_image);
      if($extension) {
        make_thumb($images_dir.$file,$thumbnail_image,$thumbs_width);
      }
    }
    echo '<a href="',$images_dir.$file,'" class="photo-link smoothbox" rel="gallery"><img src="',$thumbnail_image,'" /></a>';
    if($index % $images_per_row == 0) { echo '<div class="clear"></div>'; }
  }
  echo '<div class="clear"></div>';
}
else {
  echo '<p>There are no images in this gallery.</p>';
}

I have done a similar thing a while ago. So, yes, this is possible. You may search "php gallery without database". All you need is to specify a path to your Dropbox's images directory and make it accessible via web.

Do you need to learn how Dropbox works? In a two words: it syncs a local directory (let's say "C:/Dropbox/gallery/" at photographer's computer) with Dropbox's servers. After that, every other instance of Dropbox where installed and signed in with photographer's account will get and apply any changes of "C:/Dropbox/Gallery/" to the their own copy (let's say, "/var/www/Dropbox/gallery" e.g. on the web-server).

So, first of all you need to install Dropbox on the web server (https://www.dropbox.com/install?os=lnx). Is it problem? If yes, you need to find another way. If not, you may just write a simple function/class which will scan served web dir (like /var/www/Dropbox/gallery) for images and generate a web-accessible paths to the images.

Simplest example:

<?php
$images = glob("/var/www/Dropbox/gallery/*.*");
for ($i=0; $i<count($files)-1; $i++)
{
    $img = $images[$i];
    echo '<img src="/'.$img.'" alt="random image" />";
}
?>

Also, you maybe interested in this: My PHP DropBox Gallery 1.0 Beta

I think I found a very good solution for beginners like me. Drop box is rather restrictive of what you can do with it. However, you can sync an FTP folder and sub directories via an FTP client. I use the open source WINSCP. I let it run in the background. It constantly scans both ftp and dropbox folders for sync. If a file disappears from one folder, it disappears from the other. Therefore you can use dropbox to edit the photos in your gallery and use the javascript above to create an awesome light-box. There are probably other solutions, but I found this to be VERY simple. Also, you can simply retrieve files and delete them from dropbox if you are worried about space. I know this was posted a year ago, but I just spent the entire day trying to mess with dropbox core api and it is unfortunately over my head.

you could also try to pull the images with the dropbox chooser.

Michael

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!