开发者

any idea how pics upload site save there pics?

开发者 https://www.devze.com 2023-01-28 04:39 出处:网络
its more to a architecture related question, sorry if i ask in the wrong stack. do they put them in a large pile im a folder ?

its more to a architecture related question, sorry if i ask in the wrong stack.

do they put them in a large pile im a folder ? like

$uid.$md5(random).$nam开发者_如何学Pythone save in one folder

folder/5231.124wdadace123214.arandomname.jpg
folder/42.15125dawdaowdaw232.arandom2name.png
folder/etc

or

$uid/$md5(random).$name

5231(uid)/12421adwawda2321.arandomname.jpg
42/15125awdawdwadwa232.arandom2name.png
etc/2323awdwadwadaw.logo.png

what im thinking here is the second one is better?

because at windows i have a lot of pics in one folder

and yes it takes time to open it.

do you guys have any idea how they keep the files ?


I wrote a function for my sites that converts user ids into a two level subdirectory hierarchy that limits subdirectories to 1000 at each level.

function get_image_dir($gid) {
    $d = str_split(str_pad($gid, 6, "0", STR_PAD_LEFT), 3);
    $wdir = "/images/members/" . $d[0] . "/" . $d[1] . "/" . $gid;
    return $wdir;
}

(I actually add a third level with the raw user id to handle the rollover at 1,000,000.

/images/members/000/001/1
/images/members/000/002/2
...
/images/members/999/999/999999
/images/members/000/000/1000000
/images/members/000/001/1000001

Within those subdirectories, I further segregate based on

  1. albums (organized by members)
  2. various resizings (for different places on the site

Final structure looks something like

/images/members/000/001/1/album1/original
/images/members/000/001/1/album1/50x50
/images/members/000/001/1/album1/75x75
/images/members/000/001/1/album1/400x300

The str_split(str_pad()) in the function probably isn't optimal, but for now it works.


This depends mainly on the filesystem. For a modern filesystem like NTFS or ext3, keeping huge numbers of files in the same directory is not a problem, but some older filesystems could not handle it.

However, it may still be a good idea to partition the files into subdirectories according to some scheme, just to keep them manageable with various tools (which may have their own issues with humongous directories) such as backup. BTW, opening a directory in Windows explorer counts as such a case.


it depends how many images you're expecting to have if we're talking about thousand keeping the pictures in diffrent folders make's it easier for the computer to scan the directory for the file


The way i do it is using folder which contain id numbers,

/img/0-100/1
/img/101-200/102

This will give you an easy way of looking up your images and the folder will stay quite small. And there's no extension because i save this in the database.


Yes, lots of files in one folder can slow down seeks for files in that folder. At least in the major OSs. In theory it doesn't have to be that way.

Other sites use the date too. Not just user ids or image ids. Just another way to do the same thing.

0

精彩评论

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