diff --git a/modules/system/system.api.php b/modules/system/system.api.php
index 18cd7fe..03394f0 100644
--- a/modules/system/system.api.php
+++ b/modules/system/system.api.php
@@ -2681,22 +2681,21 @@ function hook_file_delete($file) {
  *   NULL.
  *
  * @see file_download()
- * @see upload_file_download()
  */
 function hook_file_download($uri) {
   // Check if the file is controlled by the current module.
   if (!file_prepare_directory($uri)) {
     $uri = FALSE;
   }
-  $result = db_query("SELECT f.* FROM {file_managed} f INNER JOIN {upload} u ON f.fid = u.fid WHERE uri = :uri", array('uri' => $uri));
-  foreach ($result as $file) {
-    if (!user_access('view uploaded files')) {
-      return -1;
+  if (!user_access('access user profiles')) {
+    // Access to the file is denied.
+    return -1;
+  }
+  else {
+    if (strpos(file_uri_target($uri), variable_get('user_picture_path', 'pictures') . '/picture-') === 0) {
+      $info = image_get_info($uri);
+      return array('Content-Type' => $info['mime_type']);
     }
-    return array(
-      'Content-Type' => $file->filemime,
-      'Content-Length' => $file->filesize,
-    );
   }
 }
 
