Storing a large number of images

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

    I worked on an Electronic Document Management system a few years ago, and we did pretty much what Gamecat and wic suggested.

    That is, assign each image a unique ID, and use that to derive a relative path to the image file. We used MOD similar to what wic suggested, but we allowed 1024 folders/files at each level, with 3 levels, so we could support 1G files.

    We stripped off the extension from the files however. The DB records contained the MIME Type, so extension was not needed.

    I would not recommend storing the full URL in the DB record, only the Image ID. If you store the URL you can't move or restructure your storage without converting your DB. A relative URL would be ok since that way you can at least move the image repository around, but you'll get more flexibility if you just store the ID and derive the URL.

    Also, I would not recommend allowing direct references to your image files from the web. Instead, provide a URL to a server-side program (e.g., Java Servlet), with the Image ID being supplied in the URL Query (http://url.com/GetImage?imageID=1234).

    The servlet can use that ID to look up the DB record, determine MIME Type, derive the actual location, check for security restrictions, logging, etc.

提交回复
热议问题