php檢查上傳檔案是否已存在或同名

來源:互聯網
上載者:User
//檢查上傳檔案的目錄裡是否已存在同名的上傳檔案

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."/".$_file) && $_file != "." && $_file!=".." && $_file!=="Thumbs.db"){if(eregi('/'.$file,'/'.$_file)){array_push($folder_array,$path."/".$_file);}searchFile($path."/".$_file,$file);//檢索檔案}elseif(is_file($path."/".$_file) && $_file!="." && $_file!=".." && $_file!=="Thumbs.db"){echo $_file;echo '<br>';//$_file = auto_charset($_file,'utf-8','gbk');if(eregi('/'.$file,'/'.$_file)){array_push($file_array,$path."/".$_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'; //檔案不存在}}
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.