Hashed directory creation for storing thousands of images on file system

Created on 13 August 2007, over 17 years ago
Updated 31 October 2023, over 1 year ago

As per http://drupal.org/node/29052#comment-43811, storing thousands of images in a single directory (files/images) will result in a slowdown of file system calls. I propose that images be stored in hashed directories after upload. There should be an option under "File paths" on admin/settings/image to enable or disable hashed directory creation.

You could use a basic ELF hash to determine the path based on image name. Sample code:

function hashpath($name) {
  $ulHash = 0; 
  for ($i=0; $i < strlen($name); $i++) {
    $ulHash = ( $ulHash << 4 ) + ord(substr($name, $i, 1));
    if ( $g = $ulHash & 0xF0000000 ) {
      $ulHash ^= $g >> 24;
    }
    $ulHash &= ~$g;
  }
  
  $iChar0 = $ulHash & 15;
  $ulHash = $ulHash >> 4;
  $iChar1 = $ulHash & 15;
  $ulHash = $ulHash >> 4;
  $iChar2 = $ulHash & 15;
  $ulHash = $ulHash >> 4;
  $iChar3 = $ulHash & 15;
  return sprintf("/%x/%x/%x/%x/%s", $iChar0, $iChar1, $iChar2, $iChar3, $name);
}

My company needs this functionality in order to use image.module. Would you be interested in this addition if I submitted a patch? I'd like this functionality in place so that we could take advantage of future versions of image.module.

Feature request
Status

Closed: duplicate

Version

1.0

Component

image.module

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

No activities found.

Production build 0.71.5 2024