Storing a large number of images

后端 未结 12 779
没有蜡笔的小新
没有蜡笔的小新 2020-12-07 09:25

I\'m thinking about developing my own PHP based gallery for storing lots of pictures, maybe in the tens of thousands.

At the database I\'ll point to the url of the i

12条回答
  •  情歌与酒
    2020-12-07 09:58

    When saving files associated with an auto_increment ids, I use something like the following, which creates three directory levels, each comprised of 1000 dirs, and 100 files in each third-level directory. This supports ~ 100 billion files.

    if $id = 99532455444 then the following returns /995/324/554/44

    function getFileDirectory($id) {
        $level1 = ($id / 100000000) % 100000000;
        $level2 = (($id - $level1 * 100000000) / 100000) % 100000;
        $level3 = (($id - ($level1 * 100000000) - ($level2 * 100000)) / 100) % 1000;
        $file   = $id - (($level1 * 100000000) + ($level2 * 100000) + ($level3 * 100));
    
        return '/' . sprintf("%03d", $level1)
             . '/' . sprintf("%03d", $level2)
             . '/' . sprintf("%03d", $level3)
             . '/' . $file;
    }
    

提交回复
热议问题