Image upload storage strategies

后端 未结 7 651
天命终不由人
天命终不由人 2020-12-04 07:01

When a user uploads an image to my site, the image goes through this process;

  • user uploads pic
  • store pic metadata in db, giving the image a unique id
7条回答
  •  臣服心动
    2020-12-04 07:33

    MediaWiki generates the MD5 sum of the name of the uploaded file, and uses the first two letters of the MD5 (say, "c" and "f" of the sum "cf1e66b77918167a6b6b972c12b1c00d") to create this directory structure:

    images/c/cf/Whatever_filename.png
    

    You could also use the image ID for a predictable upper limit on the number of files per directory. Maybe take floor(image unique ID / 1000) to determine the parent directory, for 1000 images per directory.

提交回复
热议问题