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.
精彩评论