Thinkphp checks whether the next object already exists

Source: Internet
Author: User
Thinkphp checks whether a file has been uploaded ** + -------------------- * check whether an uploaded file with the same name exists in the directory of the uploaded file + ------------------ * @ static * @ accesspublic + ----------- thinkphp already exists
/** + ---------------------- * Check whether a file with the same name already exists in the directory of the uploaded file + -------------------- * @ static * @ access public + -------------------- * @ param string $ path * @ param string $ file name (including the extension) + ---------------------- * @ return yes indicates that the file exists, and no indicates that the file does not exist + ------------------ */public function searchFile ($ path, $ file) {$ file_array = array (); // store the array of file names $ folder_array = array (); // store the array of directory names $ all_array = array (); // Save Put 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 ($ this-> folder_array, $ path. "/". $ _ file) ;}$ this-> searchFile ($ path. "/". $ _ file, $ file); // retrieves a file} elseif (is_file ($ path. "/". $ _ file) & $ _ file! = "." & $ _ File! = "..." & $ _ File! = "Thumbs. db ") {// $ _ file = auto_charset ($ _ file, 'utf-8', 'gbk'); if (eregi ('/'. $ file ,'/'. $ _ file) {array_push ($ this-> 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 }}

?

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.