Discussion on the structure of file storage directory in the development of Web site _ related skills

Source: Internet
Author: User
For a small number of users write interest, a large number of users are looking at information on the Web site: such as CMS system, edit send advice, users see, such as small and medium-sized products publishing site. For this kind of requirement, we can put the file into a directory, for example, put it in the upload directory of the root directory of the website, then build the folder by the day, put the daily files in a directory, the file name can be generated by number. For example: upload/20100612/1224455.jpg; In general, this directory structure guarantees that there will not be too many files in each directory.

For blogs, forum applications, the need for each user to allocate file storage space, if there is a need to limit the user's storage space, for the general size of the site directory structure can be used id+ date of the form of the user, such as upload/234/20100612/abc.jpg. If the scale is large, you can distribute the file to several different servers, can be based on the user ID a distribution rules, each server with a different domain name, and in the database to store the full URL of the file, in this case the path structure is usually: yun_qi_img/abc.jpg.

I have observed the path structure of Microsoft's file download file, which is a path generated with a GUID, for example: http://download.microsoft.com/download/5/6/7/ 567758a3-759e-473e-bf8f-52154438565a/dotnetfx.exe The structure directory is the first three bits of the GUID and the GUID makes a Level 4 directory, in which case it is guaranteed that there will not be many directories in each directory, Because it is a GUID, each file is placed in a single directory, which should be a good choice for Web sites to download.

There are web2.0 Web site will involve the user head of the storage, the head of the storage is more special, a user fixed there are a few sizes of pictures, we analyze a happy net and Sina's avatar address to see how they do the storage
1. Happy net of storage, the following are two link addresses, the first of each pair is avatar address, the second is the user's home page, the first parameter is the user ID

Http://pic1.kaixin001.com.cn/logo/13/39/50_133973_82.jpg

http://www.kaixin001.com/home/?uid=133973

http://www.kaixin001.com/home/?uid=36131662

Yun_qi_img/antilink.gif

It can be seen that the storage of happy net is stored to a few different servers, the Avatar address is based on the user ID to partition the directory do storage, the first 4 bits of ID is divided into two directories, filename with a prefix + user id+ suffix of the way to do storage.
2. The following is the address of two pairs of Sina's space, and the address of the blog avatar

http://space.sina.com.cn/u/1642511512

http://portrait1.sinaimg.cn/1642511512/blog/180

http://space.sina.com.cn/u/1725778305

http://portrait2.sinaimg.cn/1725778305/blog/180

Sina Blog Head Storage Way and happy different, is the user ID to do a level of directory, and then add a blog (should be the name of the application) plus a number 180 (conjecture may be the number of Avatar type); Sina and happy difference is no picture extension, Guess it's possible to put the avatar into a database of key-value pairs, take the picture data from the key value to the database according to the URL parameter, and then output it to the client.

From the above analysis can be guessed that happiness may be a direct deposit of the file, and Sina may be stored in the key value of the database, if the amount of data is very large, it should be Sina's way according to scalability.

Finally, we have to mention the way to store the blog for our service, the following address:

Http://pic.cnblogs.com/face/u15230.jpg

Http://pic.cnblogs.com/face/u105416.png

Http://pic.cnblogs.com/face/u40200.png

Very simple intuitive should be placed in a directory, the direct user ID file name, no directory structure, so in the folder too many files will cause performance problems?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.