A piece of php code to detect whether the remote file exists
Release: 2016-07-25 09:00:49
Original
762 people have browsed it
-
-
/** - php detects whether the remote file exists
- by http://bbs.it-home.org
- */
- function get_http_response_code($theURL) {
- $headers = get_headers($theURL);
- return substr($headers[0] , 9, 3);
- }
/**
- * Fetches all the real headers sent by the server in response to a HTTP request without redirects
- * Gets the headers without redirects
- */
- function get_real_headers($url,$format=0,$follow_redirect=0) {
- if (!$follow_redirect ) {
- //set new default options
- $opts = array('http' =>
- array('max_redirects'=>1,'ignore_errors'=>1)
- );
- stream_context_get_default($opts);
- }
- //get headers
- $headers=get_headers($url,$format);
- //restore default options
- if (isset($opts)) {
- $opts = array('http' =>
- array ('max_redirects'=>20,'ignore_errors'=>0)
- );
- stream_context_get_default($opts);
- }
- //return
- return $headers;
- }
- ?>
-
Copy code
For curl judgment method, please refer to: php code for using curl to judge whether a remote file exists . |
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31