Php checks whether an uploaded file exists or has the same name. check whether there is an uploaded file functionsearchFile ($ path, $ file) {$ file_arrayarray () in the directory of the uploaded file (); store the file name array $ folder_arrayarray (); store the directory name array $ all_arrayarray (); store all paths. php: Check whether the uploaded file already exists or has the same name.
// Check whether a file with the same name already exists in the directory of the uploaded file
Function searchFile ($ path, $ file) {$ file_array = array (); // stores an array of file names $ folder_array = array (); // store the directory name array $ all_array = array (); // store the array of all paths if (is_dir ($ path )) {// check whether the file directory exists $ H = @ opendir ($ path); while (false! ==( $ _ File = readdir ($ H) {// Retrieve the 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); // retrieves a 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 existence }}// $ 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'; // file existence} else {return 'no '; // file does not exist} else {return 'no'; // file does not exist }}
?