diff --git a/includes/file.inc b/includes/file.inc
index 2e8cd7b446836f5f2b5b6740b701e8b5f11b2b4d..963dce118940207e81e0f4527b045dd3e4fc64c4 100644
--- a/includes/file.inc
+++ b/includes/file.inc
@@ -14,7 +14,7 @@
  *
  *     function module_insert($node) {
  *       if ($node->file) {
- *         file_save($node->file);
+ *         file_save_upload($node->file);
  *       }
  *     }
  *   @endcode
@@ -29,13 +29,12 @@
  * Create the download path to a file.
  */
 function file_create_url($path) {
+  if (strpos($path, variable_get('file_directory_path', 'files')) !== false) {
+    $path = trim(substr($path, strlen(variable_get('file_directory_path', 'files'))), '\\/');
+  }
   switch (variable_get('file_downloads', FILE_DOWNLOADS_PRIVATE)) {
     case FILE_DOWNLOADS_PUBLIC:
-    case FILE_DOWNLOADS_PRIVATE:
       global $base_url;
-      if (strpos($path, variable_get('file_directory_path', 'files')) !== false) {
-        $path = trim(substr($path, strlen(variable_get('file_directory_path', 'files'))), '\\/');
-      }
       return $base_url .'/'. variable_get('file_directory_path', 'files') .'/'. str_replace('\\', '/', $path);
     case FILE_DOWNLOADS_PRIVATE:
       return url('system/files', 'file='. $path);
@@ -324,7 +323,7 @@ function file_download() {
       }
     }
   }
-  //drupal_not_found();
+  drupal_not_found();
 }
 
 /**
diff --git a/modules/profile.module b/modules/profile.module
index 38f44212c4107db7e293e2be691a72b60a516cc6..62e942b89bb9e33ec31a2aea3e7496c4b7b5fd61 100644
--- a/modules/profile.module
+++ b/modules/profile.module
@@ -219,8 +219,27 @@ function _profile_user_view(&$user, $mode) {
 }
 
 function profile_file_download($file) {
-  if (strpos($file, variable_get("profile_avatar_path", "avatars")) === 0) {
-    return array("Content-type: $mime");
+  if (strpos($file, variable_get("profile_avatar_path", "avatars") . FILE_SEPARATOR . 'avatar-') === 0) {
+    list($width, $height, $type, $attr) = getimagesize(file_create_path($file));
+    $types = array(
+      IMAGETYPE_GIF => 'image/gif',
+      IMAGETYPE_JPEG => 'image/jpeg',
+      IMAGETYPE_PNG => 'image/png',
+      IMAGETYPE_SWF => 'application/x-shockwave-flash',
+      IMAGETYPE_PSD => 'image/psd',
+      IMAGETYPE_BMP => 'image/bmp',
+      IMAGETYPE_TIFF_II => 'image/tiff',
+      IMAGETYPE_TIFF_MM  => 'image/tiff',
+      IMAGETYPE_JPC => 'application/octet-stream',
+      IMAGETYPE_JP2 => 'image/jp2',
+      IMAGETYPE_JPX => 'application/octet-stream',
+      IMAGETYPE_JB2 => 'application/octet-stream',
+      IMAGETYPE_SWC => 'application/x-shockwave-flash',
+      IMAGETYPE_IFF => 'image/iff',
+      IMAGETYPE_WBMP => 'image/vnd.wap.wbmp',
+      IMAGETYPE_XBM => 'image/xbm'
+    );
+    return array('Content-type: '. $types[$type]);
   }
 }
 
diff --git a/modules/profile/profile.module b/modules/profile/profile.module
index 38f44212c4107db7e293e2be691a72b60a516cc6..62e942b89bb9e33ec31a2aea3e7496c4b7b5fd61 100644
--- a/modules/profile/profile.module
+++ b/modules/profile/profile.module
@@ -219,8 +219,27 @@ function _profile_user_view(&$user, $mode) {
 }
 
 function profile_file_download($file) {
-  if (strpos($file, variable_get("profile_avatar_path", "avatars")) === 0) {
-    return array("Content-type: $mime");
+  if (strpos($file, variable_get("profile_avatar_path", "avatars") . FILE_SEPARATOR . 'avatar-') === 0) {
+    list($width, $height, $type, $attr) = getimagesize(file_create_path($file));
+    $types = array(
+      IMAGETYPE_GIF => 'image/gif',
+      IMAGETYPE_JPEG => 'image/jpeg',
+      IMAGETYPE_PNG => 'image/png',
+      IMAGETYPE_SWF => 'application/x-shockwave-flash',
+      IMAGETYPE_PSD => 'image/psd',
+      IMAGETYPE_BMP => 'image/bmp',
+      IMAGETYPE_TIFF_II => 'image/tiff',
+      IMAGETYPE_TIFF_MM  => 'image/tiff',
+      IMAGETYPE_JPC => 'application/octet-stream',
+      IMAGETYPE_JP2 => 'image/jp2',
+      IMAGETYPE_JPX => 'application/octet-stream',
+      IMAGETYPE_JB2 => 'application/octet-stream',
+      IMAGETYPE_SWC => 'application/x-shockwave-flash',
+      IMAGETYPE_IFF => 'image/iff',
+      IMAGETYPE_WBMP => 'image/vnd.wap.wbmp',
+      IMAGETYPE_XBM => 'image/xbm'
+    );
+    return array('Content-type: '. $types[$type]);
   }
 }