PHP Check the next file in the directory where there is already a file with the same name

Source: Internet
Author: User
PHP in the directory to check the upload file, there is already an upload file with the same name

Check to see if an uploaded file with the same name already exists in the directory where the file was uploaded

?

function Searchfile ($path, $file) {$file _array=array ();//Store file name array $folder_array=array ();//store directory an array group $all_array=array () ; Array if all paths are stored (Is_dir ($path)) {//Check file directory for presence $h = @ opendir ($path), while (False!== ($_file=readdir ($H))) {//Retrieve directory if (is_ Dir ($path. " /". $_file) && $_file! =". "&& $_file!=": "&& $_file!==" Thumbs.db ") {if (eregi ('/'. $file, '/'. $_ File) {Array_push ($folder _array, $path. ") /". $_file);} Searchfile ($path. " /". $_file, $file);//Retrieve the file}elseif (Is_file ($path." /". $_file) && $_file!=". "&& $_file!=": "&& $_file!==" Thumbs.db ") {echo $_file;echo '
';//$_file = Auto_charset ($_file, ' utf-8 ', ' GBK '), if (eregi ('/'. $file, '/'. $_file) ') {Array_push ($file _array, $path. " /". $_file); return ' yes '; File exists}}}//$this->all_array["folder"]= $this->folder_array;//$this->all_array["file"]= $this->file_ Array;closedir ($H); return ' no '; There is no}elseif (Is_file ($path)) {if (Eregi ($file, $path)) {//$this->all_array["file"]= $path; return ' yes ';//File exists} else {return ' no ';//file does not exist}}else{return ' no ';//file does not exist}}
?

?

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.