PDA

View Full Version : ask about method for saving attachment on server


sa3eka
11-29-2015, 09:44 PM
Hi everyone

I want Ask About method for saving attachments(files) on server ?
I try learn the method .
make folder for every member in Attachments folder and named by number id for member and save file uploaded by member in his foder e.x.
admin have id 1
then will be folder for his files ( attachments/1/ )
the admin upload image ( vb.png)
will saved in his file by id in attachment in data base
the directory will be
(vb/attachments/1/287.attach)

https://vborg.vbsupport.ru/external/2015/11/1.png (http://cdn.top4top.co/i_ae569592931.png)

that's correct ??

thanks

Dragonsys
11-30-2015, 01:27 AM
Basically, but user 111 will have a folder of vb/attachments/1/1/1/123.attach

sa3eka
12-02-2015, 12:54 PM
ok bro
But i want programming file(php) make me can get contact the attachment via id user and id attachment ....

how i can get it? if i have 300.000 user in my form

Dragonsys
12-02-2015, 02:34 PM
to make sure I am understanding, you want a script which will view an attachment file, in the file system, and return the contact info of the user who posted it?

sa3eka
12-02-2015, 09:58 PM
yah :) like
if i have member id is =1 and id for attachment in database is =25

http://site.com/show_attach.php?user=1&attach=25
and sorry for my English language :)

Dragonsys
12-02-2015, 11:49 PM
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):

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.

sa3eka
12-03-2015, 06:57 PM
thank u bro,
I test it,
that work for me
thanx