doudu3961 2013-04-28 05:25
浏览 37
已采纳

限制文件夹中的文件数

I have a folder name /clientupload/ in my host. I want to limit the number of files in clientupload folder and its sub-folder to total 200.

I dont have any idea how to do that!

  • 写回答

2条回答 默认 最新

  • dtewnsdf47253 2013-04-28 06:19
    关注

    you can check (via php) amount of files in folder before letting the user upload the file

    ive changes this to work with sub-folder.

    for example (you might need to change a bit didnt run this....) :

    <?php
    
      define("MAX_UPLOAD_AMOUNT", 200);
      //switch to your dir name
      $dirName = "/Temp/";
      //will count number of files
      $totalFileAmount = countFiles($dirName);
    
    function countFiles($dirName){
    
    
        $fileAmount = 0;
      //open dir
      $dir = dir($dirName);
    
      //go over the dir
      while ($file = $dir->Read()){
        //check there are no .. and . in the list
        if (!(($file == "..") || ($file == "."))){
            //check if this is a dir
            if (Is_Dir($dirName . '/' . $file)){
                //yes its a dir, check for amount of files in it 
                $fileAmount += countFiles($dirName . '/' . $file);
            }
            else{
            //its not a dir, not a .. and not a . so it must be a file, update counter
            $fileAmount++;
            }
        }
      }
    
      return $fileAmount;
    }
    
        //check if user can upload more files
        if ($totalFileAmount >= MAX_UPLOAD_AMOUNT)
            echo "You have reached the upload amount limit, no more uploaded";
        else
            echo "let the user upload the files, total number of files is $totalFileAmount"; 
    
      ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器