Discussion on the structure of file storage directory in the development of Web site _ related skills
Developer on Alibaba Coud: Build your first app with APIs, SDKs, and tutorials on the Alibaba Cloud. Read more ＞
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
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
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:
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?
This article is an English version of an article which is originally in the Chinese language on aliyun.com and is provided for information purposes only. This website makes no representation or warranty of any kind, either expressed or implied, as to the accuracy, completeness ownership or
reliability of the article or any translations thereof. If you have any concerns or complaints relating to the article, please send an email, providing a detailed description of the concern or
complaint, to firstname.lastname@example.org. A staff member will contact you within 5 working days. Once verified, infringing content will be removed immediately.
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:
and provide relevant evidence. A staff member will contact you within 5 working days.