diff -upr imagepicker-dev/imagepicker.functions.inc imagepicker/imagepicker.functions.inc
--- imagepicker-dev/imagepicker.functions.inc	2011-03-02 22:49:26.000000000 -0500
+++ imagepicker/imagepicker.functions.inc	2011-03-02 22:52:01.000000000 -0500
@@ -212,83 +212,107 @@ function imagepicker_image_page($img_id)
 /**
  * some common utilities
  */
-function imagepicker_get_path($url = FALSE, $userdir = FALSE) {
-  global $user, $base_url;
+function imagepicker_get_path($url = FALSE, $userdir = FALSE, $system = TRUE) {
+  global $base_url;
 
   $dirsep = !$url ? DIRECTORY_SEPARATOR : '/';
 
   if (!$url) {
-    $path = str_replace('/', DIRECTORY_SEPARATOR, getcwd());
-  }
-  elseif (variable_get('imagepicker_use_full_url', 0)) {
-    $path = $base_url;
+    $path = imagepicker_get_files_directory() . $dirsep;
   }
   else {
-    $path = base_path();
-    $path = preg_replace("/\/$/", "", $path);
+    if (variable_get('imagepicker_use_full_url', 0)) {
+      $path = $base_url;
+    }
+    else {
+      $path = base_path();
+      $path = preg_replace("/\/$/", "", $path);
+    }
+    $path .= $dirsep . file_directory_path() . $dirsep . IMAGEPICKER_FILES_DIR . $dirsep;
   }
 
-  $path .= $dirsep . file_directory_path() . $dirsep . IMAGEPICKER_FILES_DIR . $dirsep;
+  if ($userdir) {
+    $path .= imagepicker_get_userpath($userdir, $dirsep);
+  }
+  return $path;
+}
 
+function imagepicker_get_userpath($userdir, $dirsep = '/') {
+  global $user;
+  $path = '';
   // old or new
   $fstype = variable_get('imagepicker_fstype', '');
-
-  if ($userdir) {
-    if ($fstype == 'alpha') {
+  if ($fstype == 'alpha') {
       $username = !is_array($userdir) ? $user->name : $userdir['name'];
       $firstletter = drupal_strtolower(drupal_substr($username, 0, 1));
       $firstletter = preg_match('/^[a-z]$/', $firstletter) ? $firstletter : 'others';
       $path .= $firstletter . $dirsep . $username . $dirsep;
-    }
-    else {
+  }
+  else {
       $useruid = !is_array($userdir) ? $user->uid : $userdir['uid'];
       $path .= $useruid . $dirsep;
-    }
   }
 
   return $path;
 }
 
 function imagepicker_get_image_path($img, $type = 'browser', $public = FALSE) {
-  $imgbasedir = imagepicker_get_path(FALSE, (is_array($public) ? $public : TRUE));
+  $userdir = is_array($public) ? $public : TRUE;
+  $imgbasedir = imagepicker_get_path(FALSE, $userdir);
+  $found = FALSE;
   switch ($type) {
     case 'browser':
       if (file_exists($imgbasedir . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR . $img['img_name'])) {
-        $imgpath = imagepicker_get_path(TRUE, (is_array($public) ? $public : TRUE)) . IMAGEPICKER_BROWSER_DIR .'/'. $img['img_name'];
+        $suffix = IMAGEPICKER_BROWSER_DIR;
+	$found = TRUE;
       }
       elseif (file_exists($imgbasedir . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR . $img['img_name'])) {
-        $imgpath = imagepicker_get_path(TRUE, (is_array($public) ? $public : TRUE)) . IMAGEPICKER_THUMBS_DIR .'/'. $img['img_name'];
+        $suffix = IMAGEPICKER_THUMBS_DIR;
+	$found = TRUE;
       }
       break;
 
     case 'full':
       if (file_exists($imgbasedir . $img['img_name'])) {
-        $imgpath = imagepicker_get_path(TRUE, (is_array($public) ? $public : TRUE)) . $img['img_name'];
+        $suffix = NULL;
+	$found = TRUE;
       }
       break;
 
     case 'thumb':
     default:
       if (file_exists($imgbasedir . IMAGEPICKER_THUMBS_DIR . DIRECTORY_SEPARATOR . $img['img_name'])) {
-        $imgpath = imagepicker_get_path(TRUE, (is_array($public) ? $public : TRUE)) . IMAGEPICKER_THUMBS_DIR .'/'. $img['img_name'];
+        $suffix = IMAGEPICKER_THUMBS_DIR;
+	$found = TRUE;
       }
       elseif (file_exists($imgbasedir . IMAGEPICKER_BROWSER_DIR . DIRECTORY_SEPARATOR . $img['img_name'])) {
-        $imgpath = imagepicker_get_path(TRUE, (is_array($public) ? $public : TRUE)) . IMAGEPICKER_BROWSER_DIR .'/'. $img['img_name'];
+        $suffix = IMAGEPICKER_BROWSER_DIR;
+	$found = TRUE;
       }
       break;
 
     case 'watermarks':
       if (file_exists($imgbasedir . $img['img_name'])) {
-        $imgpath = imagepicker_get_path(TRUE, (is_array($public) ? $public : TRUE)) . IMAGEPICKER_WATERMARK_DIR .'/'. $img['img_name'];
+        $suffix = IMAGEPICKER_WATERMARK_DIR;
+	$found = TRUE;
       }
       break;
 
     case 'orig':
       if (file_exists($imgbasedir . $img['img_name'])) {
-        $imgpath = imagepicker_get_path(TRUE, (is_array($public) ? $public : TRUE)) . IMAGEPICKER_ORIG_DIR .'/'. $img['img_name'];
+        $suffix = IMAGEPICKER_ORIG_DIR;
+	$found = TRUE;
       }
       break;
   }
+  if ($found) {
+    if ($suffix) {
+      $imgpath = file_create_url(IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $suffix . '/' . $img['img_name']);
+    }
+    else {
+      $imgpath = file_create_url(IMAGEPICKER_FILES_DIR . '/' . imagepicker_get_userpath($userdir) . $img['img_name']);
+    }
+  }
 
   return $imgpath ? $imgpath : '';
 }
@@ -1867,9 +1891,20 @@ function imagepicker_browse_order_form_s
   }
 }
 
-function imagepicker_get_files_directory() {
-  $drupaldir = str_replace('/', DIRECTORY_SEPARATOR, getcwd()) . DIRECTORY_SEPARATOR;
-  $dir = $drupaldir . file_directory_path() . DIRECTORY_SEPARATOR . IMAGEPICKER_FILES_DIR;
+function imagepicker_get_files_directory($system_only = FALSE) {
+  include_once(drupal_get_path('module', 'imagepicker') . '/imagepicker.module');
+  include_once('./includes/file.inc');
+  $drupal_path = file_directory_path();
+  if (variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC) == FILE_DOWNLOADS_PRIVATE) {
+    $drupaldir = $drupal_path;
+  }
+  else {
+    $drupaldir = str_replace('/', DIRECTORY_SEPARATOR, getcwd()) . DIRECTORY_SEPARATOR . $drupal_path;
+  }
+  if ($system_only) {
+    return $drupaldir;
+  }
+  $dir = $drupaldir . DIRECTORY_SEPARATOR . IMAGEPICKER_FILES_DIR;
   return $dir;
 }
 
@@ -2924,4 +2959,3 @@ function imagepicker_uploadprogress_call
 
   exit;
 }
-
diff -upr imagepicker-dev/imagepicker.install imagepicker/imagepicker.install
--- imagepicker-dev/imagepicker.install	2011-03-02 22:49:27.000000000 -0500
+++ imagepicker/imagepicker.install	2011-03-02 22:49:26.000000000 -0500
@@ -9,9 +9,9 @@
  * Implementation of hook_install().
  */
 function imagepicker_install() {
+  include_once('imagepicker.functions.inc');
   // Create a directory structure.
-  $drupaldir = str_replace('/', DIRECTORY_SEPARATOR, getcwd()) . DIRECTORY_SEPARATOR;
-  $dir = $drupaldir . file_directory_path() . DIRECTORY_SEPARATOR .'imagepicker';
+  $dir = imagepicker_get_files_directory();
 
   if (file_check_directory($dir, TRUE)) {
     drupal_get_messages('status', TRUE);
diff -upr imagepicker-dev/imagepicker.module imagepicker/imagepicker.module
--- imagepicker-dev/imagepicker.module	2011-03-02 22:49:27.000000000 -0500
+++ imagepicker/imagepicker.module	2011-03-02 22:49:26.000000000 -0500
@@ -567,7 +567,7 @@ function imagepicker_display_block($i) {
   $textarea = variable_get('imagepicker_galleryblocks_text_'. $i, '');
   $group = imagepicker_get_user_group($gid);
   $gal = $group->group_name;
-  $fpath .= file_directory_path() . DIRECTORY_SEPARATOR . IMAGEPICKER_FILES_DIR . DIRECTORY_SEPARATOR;
+  $fpath .= imagepicker_get_files_directory() . DIRECTORY_SEPARATOR . IMAGEPICKER_FILES_DIR . DIRECTORY_SEPARATOR;
   $sql = "SELECT DISTINCT i.img_id, i.uid, i.img_name, i.img_title, img_description
   FROM {imagepicker} AS i JOIN {users} AS n USING (uid),
   {imagepicker_user_groups} AS u JOIN {imagepicker_group_images} AS g USING (gid)
@@ -807,3 +807,25 @@ function imagepicker_get_all_groups($ove
   }
   return $data;
 }
+
+/**
+ * Implementation of hook_file_download().
+ */
+function imagepicker_file_download($filepath) {
+  $imgbasedir = imagepicker_get_files_directory(TRUE);
+  $file = $imgbasedir . DIRECTORY_SEPARATOR . $filepath;
+  if (file_exists($file) & is_file($file)) {
+    // There is a file, and it's in our directory structure. So send it.
+    $mimetype = file_get_mimetype($filepath);
+    return array('Content-type:' . $mimetype);
+  }
+  else {
+    $path_parts = explode('/', $filepath);
+    if ($path_parts[0] == IMAGEPICKER_FILES_DIR) {
+      // The file is allegedly in our directory, but doesn't exist. 
+      return -1;
+    }
+  }
+  // Not our file; let someone else decide.
+  return NULL;
+}
