dongtangze6393 2009-08-06 13:35
浏览 31
已采纳

如何通过数学获得每个文件夹的X量文件?

I actually have it done, I did this math equation about 2 years ago and I am having trouble understanding it now.

Basicly I use this so that when users upload photos to my site, I can balance them out with only X amount of photo per folder.

This gives me something like this 1/1 1/2 1/3 1/4 ----1/10 2/1 2/2 2/3 and so on but I need to modify it to go 3 folders deep, each folder should have a limit of the number 1-9 or 1-10 then it will increase that number to the next

So if a large enough number is entered into my function below and the result is 3/10 then when the right number of objects is reached it would bump up to 4/1 then when so many thousands objects go by again it will jump to 4/2. What I am wanting to do is make it 3 numbers/levels deep 3/10/2 would go to 3/10/3 when it got to 3/10/10 it would go 4/1/1 4/1/2 4/1/3 when the third place got to 10 it would make it got to 4/2/1

<?PHP
function uploadfolder($x) { 
  $dir = floor($x/18001) + 1;
  $sdir = ceil($x/2000) % 9;
  return "$dir/$sdir";
}
?>

I spent a lot of time 2 years ago to get it to do this with 2 levels deep and I just kind of got lucky and now it is somewhat confusing for me looking back at it

  • 写回答

1条回答 默认 最新

  • duanqinqiao4844 2009-08-06 13:54
    关注

    It seems to do roughly this:

    It will package 2000 pictures into a subdirectory (0..8) using the line

     $sdir = ceil($x/2000) % 9
    

    Spelled out: how many times does 2000 fit into $x. As you limit this to 9 subdirectories using the modulo 9, you would get the 18001rst photo into subdirectory 0 again.

    The upper level changes therefore using 18001 as limit. All photos from 1..18000 go into directory 1. (The +1 just shifts the interval to start from 1. That is the line

    $dir = floor($x/18001) + 1;
    

    Now you could go about it like this for 3 levels (pseudocode, as I do not know PHP):

    function uploadfolder($x) {
      $numOfPics = 2000;
      $numOfFolders = 9;
    
      $topdir = ceil($x / ($numOfPics * $numOfFolders * $numOfFolders));
      $middir = floor($x / ($numOfPics * $numOfFolders)) % $numOfFolders + 1;
      $botdir = (floor($x / $numOfPics) % $numOfFolders) + 1;
      return "$topdir/$middir/$botdir";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大