开发者

How Can I Store My Images On The Server

开发者 https://www.devze.com 2022-12-27 14:17 出处:网络
How do I store a photo on the server. I store them in a directory - \"D:\\zjm_code\\basic_pr开发者_开发知识库oject\\pinax\\media\\default\\pinax\\images\\upload\" but this now a lot of images.

How do I store a photo on the server.

I store them in a directory - "D:\zjm_code\basic_pr开发者_开发知识库oject\pinax\media\default\pinax\images\upload" but this now a lot of images.

Is there another simple way?

Thanks


When you store all the images in one directory it could quickly become unmanaged due to huge number of files. You can put your images in subdirectories based on md5 or sha1 hash function. Usually 2 levels of subdirs is enough.

In this case your directory images/upload will contain subdirs with the names 00, 01, 02 .. FF (256 names total) and each of these 256 directories in turn will contain directories with names 00 through FF giving you in total 256*256 directories on level 2.

For each uploaded file you calculate hash function (not necessary based on it's content, but on some unique data) and take [0:2] as a name of first directory and [2:4] as a name of second level directory.

This would be helpful in creating directories: mkdir -p functionality in Python


There are two common options.

1) Store them on the file system on the server, preferably not all in one directory - but split logically.

2) Store the images in a database, if you are using MySql you would do this using the "blob" type.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号