You are here

README.txt in File Hash 8

Same filename and directory in other branches
  1. 7 README.txt
FILE HASH
=========

INTRODUCTION
------------

Hashes of uploaded files, which can be found on a variety of sites from
archive.org to wikileaks.org, allow files to be uniquely identified, allow
duplicate files to be detected, and allow copies to be verified against the
original source.

File Hash module generates and stores MD5, SHA-1 and/or SHA-256 hashes for each
file uploaded to the site.

REQUIREMENTS
------------

Drupal core File module is required.

INSTALLATION
------------

Install as you would normally install a contributed Drupal module.

CONFIGURATION
-------------

Hash algorithms can be enabled and disabled by the site administrator at
admin/config/media/filehash.

File hashes for pre-existing files will be generated "lazily," on demand, but
you can generate them in bulk at admin/config/media/filehash/generate or by
running `drush fgen`.

Hash values are loaded into the $file object where they are available to the
theme and other modules.

Handlers are provided for Views module compatibility. In addition, a
<media:hash> element is added for file attachments in node RSS feeds (file,
image, and media field types are supported).

Tokens are provided for the full hashes: [file:filehash-md5],
[file:filehash-sha1], [file:filehash-sha256], as well as pairtree tokens useful
for content addressable storage.

For example, if the SHA-256 hash for a file is
e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, you could
store it in the files/e3/b0 directory using these tokens:
[file:filehash-sha256-pair-1]/[file:filehash-sha256-pair-2].

If the "disallow duplicate files" checkbox in File Hash settings is checked, any
duplicate uploaded files will be rejected site-wide. You may also leave this
setting off, and apply the dedupe validator function manually to a particular
file upload form in a custom module:

```
<?php

/**
 * Implements hook_form_FORM_ID_alter().
 */
function example_form_node_article_edit_form_alter(&$form, $form_state, $form_id) {
  foreach ($form['field_image']['widget'] as $item) {
    if (is_array($item) && isset($item['#delta'])) {
      $form['field_image']['widget'][$item['#delta']]['#upload_validators']['filehash_validate_dedupe'] = [];
    }
  }
}

```

File

README.txt
View source
  1. FILE HASH
  2. =========
  3. INTRODUCTION
  4. ------------
  5. Hashes of uploaded files, which can be found on a variety of sites from
  6. archive.org to wikileaks.org, allow files to be uniquely identified, allow
  7. duplicate files to be detected, and allow copies to be verified against the
  8. original source.
  9. File Hash module generates and stores MD5, SHA-1 and/or SHA-256 hashes for each
  10. file uploaded to the site.
  11. REQUIREMENTS
  12. ------------
  13. Drupal core File module is required.
  14. INSTALLATION
  15. ------------
  16. Install as you would normally install a contributed Drupal module.
  17. CONFIGURATION
  18. -------------
  19. Hash algorithms can be enabled and disabled by the site administrator at
  20. admin/config/media/filehash.
  21. File hashes for pre-existing files will be generated "lazily," on demand, but
  22. you can generate them in bulk at admin/config/media/filehash/generate or by
  23. running `drush fgen`.
  24. Hash values are loaded into the $file object where they are available to the
  25. theme and other modules.
  26. Handlers are provided for Views module compatibility. In addition, a
  27. element is added for file attachments in node RSS feeds (file,
  28. image, and media field types are supported).
  29. Tokens are provided for the full hashes: [file:filehash-md5],
  30. [file:filehash-sha1], [file:filehash-sha256], as well as pairtree tokens useful
  31. for content addressable storage.
  32. For example, if the SHA-256 hash for a file is
  33. e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855, you could
  34. store it in the files/e3/b0 directory using these tokens:
  35. [file:filehash-sha256-pair-1]/[file:filehash-sha256-pair-2].
  36. If the "disallow duplicate files" checkbox in File Hash settings is checked, any
  37. duplicate uploaded files will be rejected site-wide. You may also leave this
  38. setting off, and apply the dedupe validator function manually to a particular
  39. file upload form in a custom module:
  40. ```
  41. /**
  42. * Implements hook_form_FORM_ID_alter().
  43. */
  44. function example_form_node_article_edit_form_alter(&$form, $form_state, $form_id) {
  45. foreach ($form['field_image']['widget'] as $item) {
  46. if (is_array($item) && isset($item['#delta'])) {
  47. $form['field_image']['widget'][$item['#delta']]['#upload_validators']['filehash_validate_dedupe'] = [];
  48. }
  49. }
  50. }
  51. ```