• 技术文章 >后端开发 >php教程

    thinkphp检查下传文件时是否已存在

    2016-06-13 13:08:30原创207
    thinkphp检查上传文件时是否已存在
     
    
        /**
         +----------------------
         * 检查上传文件的目录里是否已存在同名的上传文件
         +----------------------
         * @static
         * @access public
         +----------------------
         * @param string $path 文件目录路径
         * @param string $file 文件名(包括扩展名)
         +----------------------
         * @return 返回yes表示文件存在,no表示文件不存在
         +----------------------
         */
      public function searchFile($path,$file){
      $file_array=array(); //存放文件名数组
      $folder_array=array(); //存放目录名数组
      $all_array=array(); //存放全部路径的数组
    
      if(is_dir($path)){  //检查文件目录是否存在
       $H = @ opendir($path);
       while(false !== ($_file=readdir($H))){
        //检索目录
        if(is_dir($path."//m.sbmmt.com/m/".$_file) && $_file != "." && $_file!=".." && $_file!=="Thumbs.db"){
         if(eregi('//m.sbmmt.com/m/'.$file,'//m.sbmmt.com/m/'.$_file)){
          array_push($this->folder_array,$path."//m.sbmmt.com/m/".$_file);
         }
         $this->searchFile($path."//m.sbmmt.com/m/".$_file,$file);
        //检索文件
        }elseif(is_file($path."//m.sbmmt.com/m/".$_file) && $_file!="." && $_file!=".." && $_file!=="Thumbs.db"){
         //$_file = auto_charset($_file,'utf-8','gbk');
         if(eregi('//m.sbmmt.com/m/'.$file,'//m.sbmmt.com/m/'.$_file)){
          array_push($this->file_array,$path."//m.sbmmt.com/m/".$_file);
          return 'yes'; //文件存在
         }
        }
       }
       //$this->all_array["folder"]=$this->folder_array;
       //$this->all_array["file"]=$this->file_array;
       closedir($H);
       return 'no'; //不存在
      }elseif(is_file($path)){
       if(eregi($file,$path)){
        //$this->all_array["file"]=$path;
        return 'yes'; //文件存在
       } else {
        return 'no'; //文件不存在
       }
      }else{
       return 'no'; //文件不存在
      }
     }
    

    ?

    声明:本文原创发布php中文网,转载请注明出处,感谢您的尊重!如有疑问,请联系admin@php.cn处理
    专题推荐:file array path amp this
    上一篇: thinkphp清空全部目录(包括子目录) 下一篇: 茂名市的PHP人才是否都不在茂名了
    大前端线上培训班

    相关文章推荐

    • 分享一份PHP开发内部规范• php session有关问题 • PHP 文件上载 • PHP学习系列5

    全部评论我要评论

  • 取消发布评论发送
  • 1/1

    PHP中文网