What are the downsides of longer directory paths/names and URL's on a LAMP site?

泄露秘密 提交于 2019-12-02 12:39:23

Having a large number of files in one directory can make it slow. You are right to split it up. You can however try to reduce the length by using all alphanumeric characters in the path names.

If you were to have:

/images/[a-z0-9]{3}/[a-z0-9]{3}/[a-z0-9]{3}.jpg
/images/abc/def/ghi.jpg

With the above you can store 101559956668416 images. This seems ridiculous so perhaps something like:

/images/[a-z0-9]{2}/[a-z0-9]{2}.jpg
/images/ab/cd.jpg

With the above you can store 1679616 images. This is a reasonable number but might not be enough for your needs. So how about this:

/images/[a-z0-9]{2}/[a-z0-9]{2}/[a-z0-9]{2}.jpg
/images/ab/cd/ef.jpg

This allows for 2176782336 (2 billion) images and each directory will only ever have a maximum of 1296 child files/directories.

Mix in some capital letters and perhaps even some symbols and you can get away with even fewer. Personally I would go with the last option though. It seems to be a nice balance.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!