well, the folder structure will always be 1 digit. So you know user #111's attachments will be in folder attachments/1/1/1/files. user #112 will be in attachments/1/1/2/files. user 345 will be in attachments/3/4/5/files etc
user #3000 = attachments/3/0/0/0/files
user #30000 = attachments/3/0/0/0/0/files
you can see that the folders stack.
Try something like this (stolen from Stack Exchange):
PHP Code:
puteveryXcharacters($userid,"/",1);
function puteveryXcharacters($str,$wha,$cnt) {
$strip = false;
if (strlen($str) % $cnt == 0) {
$strip = true;
}
$tmp = preg_replace('/(.{'.$cnt.'})/',"$1$wha", $str);
if ($strip) {
$tmp = substr($tmp,0,-1);
}
return $tmp;
}
if userid is 123 this should return 1/2/3
NOTE: This has not been tested by me, so use with caution.