There is such a function
public function get_upload_dir($id) { for($i=2;$i>=1;$i--) { $dir_file_arr[]=ceil($id/pow(1000,$i)); } $dir_file_str=implode("/", $dir_file_arr); return $dir_file_str; }
the point is that I pass the id function and it should return the path to the folder
in the loop, the number 2 is the number of folder branches
the maximum possible value of $ id is 1000 to the 3rd power, i.e. 1000 000 000 (degree - the number of branches + 1)
let's sort the function on a simple example, like this
public function get_upload_dir($id) { for($i=2;$i>=1;$i--) { $dir_file_arr[]=ceil($id/pow(3,$i)); } $dir_file_str=implode("/", $dir_file_arr); return $dir_file_str; }
maximum value here is 27
those. that's what i should get
id = 1 answer 1/1
id = 2 answer 1/1
id = 3 answer 1/1
id = 4 answer 1/2
id = 5 answer 1/2
id = 11 answer 2/4
id = 25 answer 3/9
How to fix the function so that to get the numbering in this form?
id = 1 answer 1/1
id = 2 answer 1/1
id = 3 answer 1/1
id = 4 answer 1/2
id = 5 answer 1/2
id = 11 answer 2/1
id = 25 answer 3/3
because there are 3 folders 1, 2, 3
There are 1, 2, 3 in these folders as well.
and now the function does so
there are 3 folders 1, 2, 3
each has 3 folders whose names are the ordinal number calculated by the formula