Storing a large number of images

后端 未结 12 762
没有蜡笔的小新
没有蜡笔的小新 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:32

    You may check out the stratey used by Apple iPod for storing it's multimedia content. There are folders in one level of depth and files with titles of same width. I believe that Apple guys invested a lot of time in testing their solution so it may bring some instant benefit to you.

    0 讨论(0)
  • 2020-12-07 09:32

    You can store the images in the database as blobs (varbinary for mssql). That way you don't have to worry about the storage or directory structure. The only downside is that you can't easily browse the files, but that would be hard in a balanced directory tree anyway.

    0 讨论(0)
  • 2020-12-07 09:34

    I am currently facing this problem, and what Isaac wrote got me interested in the idea. Tho my function differs a little.

    function _getFilePath($id) {
        $id = sprintf("%06d", $id);
        $level = array();
        for($lvl = 3; $lvl >= 1; $lvl--)
            $level[$lvl] = substr($id, (($lvl*2)-2), 2);
        return implode('/', array_reverse($level)).'.jpg';
    }
    

    My images are only in thousands so i only have this up to 999999 limit and so it would split that into 99/99/99.jpg or 43524 into 04/35/24.jpg

    0 讨论(0)
  • 2020-12-07 09:38

    I usually just use the numerical database id (auto_increment) and then use the modulu (%) operator to figure out where to put the file. Simple and scalable. For instance the path to image with id 12345 could be created like this:

    12345 % 100 = 45
    12345 % 1000 = 345
    

    Ends up in:

    /home/joe/images/345/45/12345.png
    

    Or something like that.

    If you're using Linux and ext3 and the filesystem, you must be aware that there are limits to the number of directories and files you can have in a directory. The limit is 32000 for dirs, so you should always strive to keep number of dirs low.

    0 讨论(0)
  • 2020-12-07 09:43

    You could alawys have a DateTime column in the table and then store them in folders named after the month,year or even month,day,year the images where added to the table.

    Example

    1. 2009
    2. -01
    3. --01
    4. --02
    5. --03
    6. --31

    this way you end up with no more then 3 folders deep.

    0 讨论(0)
  • 2020-12-07 09:44

    I know is impractical to have all of them sitting at the same directory in the server as it would slow access to a crawl.

    This is an assumption.

    I have designed systems where we had millions of files stored flat in one directory, and it worked great. It's also the easiest system to program. Most server filesystems support this without a problem (although you'd have to check which one you were using).

    http://www.databasesandlife.com/flat-directories/

    0 讨论(0)
提交回复
热议问题