You are here

function filehash_file_load in File Hash 7

Same name and namespace in other branches
  1. 8 filehash.module \filehash_file_load()

Implements hook_file_load().

File

./filehash.module, line 63
Generate hashes for each uploaded file.

Code

function filehash_file_load($files) {
  $algos = filehash_algos();
  if ($algos) {
    $result = db_select('filehash')
      ->fields('filehash')
      ->condition('fid', array_keys($files), 'IN')
      ->execute();
    foreach ($result as $record) {
      foreach ($algos as $algo) {
        $files[$record->fid]->filehash[$algo] = $record->{$algo};
      }
    }

    // Generate hash if it does not already exist for the file.
    foreach ($files as $fid => $file) {
      foreach ($algos as $algo) {
        if (empty($file->filehash[$algo])) {
          filehash_save($files[$fid]);
          break;
        }
      }
    }
  }
}