Algorithmic Approach to generating Unique traceable paths for uploads-2

To reach the unique file repository its easy right.Let us see how.

Function hashSlice just needs to be returning a substr from hash to branch out unique.Say, like below:-

return substr($hashValue,0,$num);

// pass a class attribute that is assigned/configured to a fixed length.

Logic to generate a fixed member and unique branch for attachment or upload object path for a traceable event:

function inputs are $handle, $type.
$handle = ( $username || $metafilename )
$type = ( user | usrobj )

1. Generate the hashed value with the below strategy.

$hash = 0;
for($i=0; $i < strlen($handle) ; $i++)
{
$value = substr($handle, $i, 1);
$hash = $hash*17 + ord($value);
$hash %= 9000;
}

2. Now prepare the fixed user homepath using

$home .=(1+($hash % 9));
OR
$home .=SERVER_PATH.(1+($hash % 9));

(// this is for usrobj type.)based on $type.

3. Apply bitwise shift to 3 places and get modulo of hash.

$hash >>=3;
$hash %=1000;

4. Prepare the homepath of the user as

$home .= “/$hash/$handle”;
OR
$home .= “/$hash/”;

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: