Check in php whether an uploaded file with the same name already exists in the directory of the uploaded file
Check whether an uploaded file with the same name already exists in the directory where you uploaded the file
?
function searchFile($path,$file){ $file_array=array(); //Storage array of file names $folder_array=array(); //Storage array of directory names $all_array=array(); //array to store all paths if(is_dir($path)){ //Check whether the file directory exists $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 files }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'; //The file exists } } } //$this->all_array["folder"]=$this->folder_array; //$this->all_array["file"]=$this->file_array; closedir($H); return 'no'; //does not exist }elseif(is_file($path)){ if(eregi($file,$path)){ //$this->all_array["file"]=$path; return 'yes'; //The file exists } else { return 'no'; //The file does not exist } }else{ return 'no'; //The file does not exist } }
?
?