diff --git a/protected_node.module b/protected_node.module
index c9b4b7c..84f707f 100644
--- a/protected_node.module
+++ b/protected_node.module
@@ -204,10 +204,10 @@ function protected_node_init() {
   }
   elseif (arg(0) == 'system' && arg(1) == 'files') {
     $requested_url = drupal_parse_url(request_uri());
-    $path = explode('/', $requested_url['path']);
+    $path = urldecode(str_replace('system/files', '', $requested_url['path']));
+
     if (!empty($path)) {
-      $filename = end($path);
-      $nid = protected_node_and_attachment($filename);
+      $nid = protected_node_and_attachment($path);
     }
   }
 
@@ -343,7 +343,7 @@ function protected_node_is_locked($nid, $op = 'access') {
  * @return mixed
  *   File nid if user has access. FALSE otherwise.
  */
-function protected_node_and_attachment($filename) {
+function protected_node_and_attachment($path) {
   global $user;
 
   if (user_access('edit protected content')) {
@@ -358,11 +358,48 @@ function protected_node_and_attachment($filename) {
   $query->fields('n', array('nid', 'uid'));
   $query->fields('pn', array('protected_node_passwd_changed'));
   $query->condition('fu.type', 'node');
-  $query->condition('fm.filename', $filename);
+  $query->condition('fm.uri', '%' . db_like($path), 'LIKE');
   $query->condition('pn.protected_node_is_protected', '1');
   $number_of_results = $query->countQuery()->execute()->fetchField();
+
+  // If number is 0, node is not protected, or file is in Field collection
   if (0 == $number_of_results) {
-    return FALSE; /* Row doesn't exist, it's not protected */
+    if (module_exists('field_collection')) {
+      // Check if file is attached to protected node via field collection
+      $query = db_select('file_usage', 'fu');
+      $query->join('file_managed', 'fm', 'fu.fid = fm.fid');
+      $query->fields('fu', array('id'));
+      $query->condition('fu.type', 'field_collection_item');
+      $query->condition('fm.uri', '%' . db_like($path), 'LIKE');
+      $in_field_collection = $query->countQuery()->execute()->fetchField();
+      if ($in_field_collection != '0') {
+        // The file is attached to a field collection item
+        $field_collection_id = $query->execute()->fetch();
+        $field_collection = entity_load('field_collection_item', array($field_collection_id->id));
+        $protected_nid = $field_collection[$field_collection_id->id]->hostEntity();
+
+        // Query the node table again with the nid the fiedl collection belongs to..
+        $query = db_select('node', 'n');
+        $query->join('protected_nodes', 'pn', 'n.nid = pn.nid');
+        $query->fields('n', array('nid', 'uid'));
+        $query->fields('pn', array('protected_node_passwd_changed'));
+        $query->condition('n.nid', $protected_nid->nid);
+        $query->condition('pn.protected_node_is_protected', '1');
+
+        $number_of_results = $query->countQuery()->execute()->fetchField();
+
+        if (0 == $number_of_results) {
+          return FALSE;
+        }
+      }
+      else {
+        return FALSE;
+      }
+    }
+    else {
+      // If not in node, nor in field_collection, return FALSE
+      return FALSE; /* Row doesn't exist, it's not protected */
+    }
   }
   $result = $query->execute();
 
@@ -592,7 +629,7 @@ function _protected_node_node_create_or_update($node) {
 
   // Send notifications if there is at least one email.
   if ($node->protected_node_is_protected && !empty($node->protected_node_emails) &&
-      $node->status == 1 && isset($node->protected_node_clear_passwd)) {
+    $node->status == 1 && isset($node->protected_node_clear_passwd)) {
     module_load_include('mail.inc', 'protected_node');
     protected_node_send_mail($node);
   }
@@ -825,10 +862,10 @@ function _protected_node_save(&$node) {
   // We also retrive nid because protected_node_passwd may exist and be empty.
   $result = db_select('protected_nodes')
     ->fields('protected_nodes', array(
-        'nid',
-        'protected_node_passwd',
-        'protected_node_emails',
-      ))
+      'nid',
+      'protected_node_passwd',
+      'protected_node_emails',
+    ))
     ->condition('nid', $node->nid)
     ->execute()
     ->fetchAssoc();
