PHP filter does not exist in the picture resources,
Method One:
The simplest way is to use fopen (), to see if the file can be opened, can hit the file of course exists.
<?php$url = ' http://www.bkjia.com/images/test.jpg ', if (@fopen ($url, ' R ')) { echo ' File Exits ';} else {echo ' Fil e do not Exits ';}? >
Method Two:
/** * Filter for non-existent picture resources * * @author wanggeng
* @return vodi * */ private static function _ Checkall ($url) { $curl = Curl_init ($url); curl_setopt ($curl, Curlopt_nobody, true); $result = false; $res = curl_exec ($curl); if ($res!== false) { $statusCode = Curl_getinfo ($curl, curlinfo_http_code); if ($statusCode = =) { $result = true; } } Curl_close ($curl); return $result; }
First, create a link to a curl that is linked to the execution URL, which is the picture or file.
Initial one variable is false
or open the linked Head header information each HTTP request will have an HTTP Code
We're going to verify this code.
If the return code is 200 to prove that the resource exists to a true value before the variable is not assigned the value
Method Three:
CURL method
Curl is a very useful class library, see below How to use it to judge.
<?php$url2 = ' http://www.bkjia.com/test.jpg '; $ch = Curl_init (); $timeout = 10;curl_setopt ($ch, Curlopt_url, $url 2); curl_setopt ($ch, Curlopt_header, 1); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_ ConnectTimeout, $timeout); $contents = Curl_exec ($ch);//echo $contents; if (Preg_match ("/404/", $contents)) {echo ' File does not exist ';}? >
Curl_exec () If the file does not exist after execution, the following information is returned:
http/1.1 404 Not Founddate:tue, 05:08:34 Gmtserver:apacheaccept-ranges:bytescontent-length:354content-type : text/html
Use the regular to see if there are 404, and some files do not exist.
The above mentioned is the whole content of this article, I hope you can like.
http://www.bkjia.com/PHPjc/991803.html www.bkjia.com true http://www.bkjia.com/PHPjc/991803.html techarticle PHP Filter does not exist image resources, method one: The simplest way is to use fopen (), to see if the file can be opened, the file will certainly exist. Php$url = ' http://www.bkjia.com/ ...