--- /Users/oli/Desktop/download_count/download_count.module
+++ download_count.module
@@ -129,7 +129,7 @@
   $rows = array();
   $fileDirectoryPath = file_directory_path() . '/';  
   if(user_access('view all downloads count')) {
-    $result = db_query("SELECT fd.filename, fd.count, fd.timestamp, u.nid, nt.name FROM {file_downloads} fd JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) JOIN {upload} u ON u.fid = f.fid JOIN {node} n ON n.nid = u.nid JOIN {node_type} nt ON nt.type = n.type"  . tablesort_sql($header), $fileDirectoryPath);
+		$result = db_query("SELECT fd.filename, fd.count, fd.timestamp, u.nid, nt.name FROM {file_downloads} fd JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) LEFT JOIN {upload} u ON u.fid = f.fid LEFT JOIN {node} n ON n.nid = u.nid LEFT JOIN {node_type} nt ON nt.type = n.type"  . tablesort_sql($header), $fileDirectoryPath);
   }
   else {
     $result = db_query("SELECT fd.filename, fd.count, fd.timestamp, u.nid, nt.name FROM {file_downloads} fd JOIN {files} f ON f.filepath = CONCAT('%s', fd.filename) JOIN {upload} u ON u.fid = f.fid JOIN {node} n ON n.nid = u.nid JOIN {node_type} nt ON nt.type = n.type WHERE n.uid = %d" . tablesort_sql($header), $fileDirectoryPath, $user->uid);
@@ -139,7 +139,7 @@
     $row[] = $file->filename;
     $row[] = $file->count;
     $row[] = t('@time ago', array('@time' => format_interval(time() - $file->timestamp)));
-    $row[] = l(t('view @type', array('@type' => $file->name)), 'node/' . $file->nid);
+    $row[] = $file->name ? l(t('view @type', array('@type' => $file->name)), 'node/' . $file->nid) : '';
     $rows[] = $row;
   }
   if (empty($rows)) {
@@ -163,24 +163,47 @@
     }
   }
   $filepath = file_create_path($filename);
-  $result = db_query("SELECT u.nid, f.filepath FROM {upload} u JOIN {files} f ON f.fid = u.fid WHERE f.filepath = '%s'", $filepath);
+	$result = db_query("SELECT u.nid, f.filepath FROM {files} f LEFT JOIN {upload} u ON f.fid = u.fid WHERE f.filepath = '%s'", $filepath);
   if ($file = db_fetch_object($result)) {
-    if (user_access('view uploaded files') && node_access('view', node_load($file->nid))) {
+		if($file->nid) {
+			if (user_access('view uploaded files') && node_access('view', node_load($file->nid))) {
+				watchdog('download', 'Failed to download %file', array('%file' => $filename), WATCHDOG_WARNING);
+			}
+		}
+		else {
       watchdog('download', '%file was downloaded', array('%file' => $filename), WATCHDOG_NOTICE);
       // If the file is already added, just increment the count,
       // otherwise add the file with count 1
       if(db_result(db_query("SELECT filename FROM {file_downloads} WHERE filename = '%s'", $filename))) {
         db_query("UPDATE {file_downloads} SET count = count+1, timestamp = %d  WHERE filename = '%s'", time(), $filename);
       }
-    else {
-        db_query("INSERT INTO {file_downloads} (filename, count, timestamp) VALUES ('%s', 1,%d)", $filename, time());
-    }
-  }
-  else {
-    watchdog('download', 'Failed to download %file', array('%file' => $filename), WATCHDOG_WARNING);
-  }
+	    else {
+				db_query("INSERT INTO {file_downloads} (filename, count, timestamp) VALUES ('%s', 1,%d)", $filename, time());
+	    }
+		}
   }
 }
+
+/**
+* Check if the field is a cck field. 
+* @return TRUE or FALSE
+*/
+function _download_count_cck_child($key) {
+  return (!isset($key[0]) || $key[0] != '#') && substr($key, 0, 6) == 'field_';
+}
+
+/**
+* Load filefields into $node->files. 
+*/
+function download_count_load_filefield(&$node){
+	$ccks = array_filter(array_keys((array) $node), '_download_count_cck_child');
+	foreach($ccks as $key => $cck){
+		foreach($node->$cck as $t){
+			if(array_key_exists('fid', $t))  $node->files[] = (object) $t;
+		}
+	}
+}
+
 /**
  * Implementation of hook_nodeapi()
  */
@@ -189,11 +212,16 @@
     global $user;
     if ($user->uid == 1 && variable_get('do_not_show_download_count_in_node_for_admin', FALSE)) {
         return;
-      }
-    if (!$node->teaser && count($node->files)) {
-      if (user_access('view all downloads count in nodes') || (user_access('view own nodes downloads count in nodes') && ($node->uid == $user->uid)) ) {
-        $node->body = theme('download_count_body', $node);
-      }
+    }
+
+		if (!$node->teaser) {
+			// Load all filefields into $node->files.
+			$filefields = download_count_load_filefield($node);
+			if (count($node->files) || count($filefields)) {
+	      if (user_access('view all downloads count in nodes') || (user_access('view own nodes downloads count in nodes') && ($node->uid == $user->uid)) ) {
+	        $node->body = theme('download_count_body', $node);
+	      }
+			}
     }
   }
 }
