In thinkphp, you can determine whether a remote or non-remote file exists. * function: remote_file_exists function: determines whether a remote file has a parameter: $ url_file-remote file URL $ flag-true is used to determine a remote file. if false is used to determine whether a non-remote file is returned, true is returned. If no remote file exists, or whether a remote or non-remote file exists in thinkphp
// Determine whether a remote file exists/* function: remote_file_exists function: determine whether a remote file exists. the parameter: $ url_file-remote file URL $ flag-true is used to determine the remote file, if the value is false, the system returns true if a non-remote file exists. if the file does not exist or otherwise, the system returns false */static function remote_file_exists ($ url_file, $ flag = true) {if ($ flag = true) {// The default value is to judge the remote file // Check the input $ url_file = trim ($ url_file); if (empty ($ url_file )) {return false;} $ url_arr = parse_url ($ url_file); if (! Is_array ($ url_arr) | empty ($ url_arr) {return false;} // Get request data $ host = $ url_arr ['host']; $ path = $ url_arr ['path']. "? ". $ Url_arr ['query']; $ port = isset ($ url_arr ['port'])? $ Url_arr ['port']: "80"; // connect to the server $ fp = fsockopen ($ host, $ port, $ err_no, $ err_str, 30); if (! $ Fp) {return false;} // Construct the request protocol $ request_str = "GET ". $ path. "HTTP/1.1 \ r \ n"; $ request_str. = "Host :". $ host. "\ r \ n"; $ request_str. = "Connection: Close \ r \ n"; // send the request fwrite ($ fp, $ request_str); $ first_header = fgets ($ fp, 1024 ); fclose ($ fp); // Determine whether the object exists if (trim ($ first_header) = "") {return false;} if (! Preg_match ("/200/", $ first_header) {return false;} return true;} else if ($ flag = false) {// non-remote file return file_exists ($ url_file );}}
?