Php checks whether remote files are available in advance. We use functions related to phpcurl to access remote files, and then determine whether the files can be normally used based on the returned status, if you have any need, you can refer to the following code to copy and use php curl functions to access remote files. then, you can determine whether the files can be used normally based on the returned status, for more information, see
The code is as follows: |
|
// Determine the remote file Function check_remote_file_exists ($ url) { $ Curl = curl_init ($ url ); // Do not retrieve data Curl_setopt ($ curl, CURLOPT_NOBODY, true ); // Send the request $ Result = curl_exec ($ curl ); $ Found = false; // Failed to send the request If ($ result! = False ){ // Check whether the http response code is 200. $ StatusCode = curl_getinfo ($ curl, CURLINFO_HTTP_CODE ); If ($ statusCode = 200 ){ $ Found = true; } } Curl_close ($ curl ); Return $ found; } |
Method 2
The code is as follows: |
|
$ Url = "/upload/201110/20111008192257383 .gif "; $ Array = get_headers ($ url, 1 ); If (preg_match ('/ 200/', $ array [0]) { Echo""; Print_r ($ array ); } Else { Echo "invalid url resource! "; } |
Curl-related functions to access remote files, and then determine whether the files can be normally used based on the returned status. if you need them, refer to the following code to copy the files...