Hash of Image for GUID on ABigHairy.com (the technology powerhouse behind TeddyBear.com)

The files end up in a hashed directory structure so one folder doesn’t contain a kagillion (cajillion?) files.

Meta data stored in a “hidden” dot file, alongside.

{
   "name":"2023-07-10 12_35_30-Window.jpg",
   "mime":"image\/jpeg",
   "width":468,
   "height":232,
   "getimagesize":{
      "0":468,"1":232,"2":2,
      "3":"width=\"468\" height=\"232\"",
      "bits":8,
      "channels":3,
      "mime":"image\/jpeg"
   }
}

July 20 Update

I’ve decided to store the files in a directory structure that is “hashed” to 4 levels. That means I can store a bunch of files more efficiently? This used to be true, for sure, because one doesn’t have to depend on the underlying file system’s quality of indexing method. Any file system can look up 1 in 255 folders quickly. The last folder could have many more than 255 files in it, but that’s unlikely unless I have A LOT of files. Since the files Are “hashed” with sha-1 or something like it, the values are almost random — they’ll be evenly distributed (he wrote without any evidence for his case except for a vague sense of the goals of cryptography for which hashes like SHA were created). </KOtalk>

$hash = hash_file('sha1', $_FILES["fileToUpload"]["tmp_name"]);
$hashedpath = substr($hash, 0, 2) . "/"
    . substr($hash, 2, 2) . "/"
    . substr($hash, 4, 2) . "/"
    . substr($hash, 6, 2)
;

$target_dir = "/private/uploads/" . $hashedpath;



$target_file    = $target_dir . "/" . $hash . "." . $imageFileType;
$meta_file =  $target_file . ".json";


I also decided I should not use the .dot hidden file thing for the meta information. I’m putting them in json format, so I’m tacking on the .json extension.


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.