开发者

User content Folder Structure based on UserID while hiding total users

I'm trying to figure out a folder structure for storing user content such as images, which will work for a massive amount of users. I was going to go with something like... 000/000/001 (user id 1) ....999 max subfolder per folder.

But I would like to hide t开发者_运维百科he total number of users, easily seen by starting at 1. Should I start at some random number like 349203480? I'm baffled as to how to work out the folders based on ID this way. Is there some better/easier way?


Use GUID's:

  • http://php.net/manual/en/function.uniqid.php

As per the PHP manual:

<?php
/* A uniqid, like: 4b3403665fea6 */
 printf("uniqid(): %s\r\n", uniqid());

/* We can also prefix the uniqid, this the same as 
 * doing:
 *
 * $uniqid = $prefix . uniqid();
 * $uniqid = uniqid($prefix);
 */
printf("uniqid('php_'): %s\r\n", uniqid('php_'));

/* We can also activate the more_entropy parameter, which is 
 * required on some systems, like Cygwin. This makes uniqid()
 * produce a value like: 4b340550242239.64159797
 */
printf("uniqid('', true): %s\r\n", uniqid('', true));
?>

Create unique folders, create unique sub-folders. No one, including yourself, will ever know how many you have ... unless you are doing a count of folders / sub-folders on the FileSystem or are maintaining a reference of actual users to GUID's


Well, the simplest and easiest approach would be what you suggested. Pre-start counting users with a random number.

Another way would be to append a random number to your user id.

$userid = get_user_id();
$foldername = strval($userid) . strval(rand(1, 999));

//$foldername = 11, 231, ...

But of course, the above method has the overhead of checking if the folder already exists.

A third way would be use a simple encryption (such as rot13) on the username/id and append folder count from there on.

$username = get_user_name();                 //Use the user id if you wish.
$next_folder_count = $last_folder_count + 1;
$foldername = str_rot13($username) . strval($next_folder_count);

//$foldername = hxcvf1, hxcvf2, ...

Again, you'll have to store the count of folders, or obtain it on the fly from the directory. The advantage of the last method would we that just by knowing the foldername, you can find out which user it belongs to.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜