Home >Backend Development >PHP Tutorial >Determine the existence of remote images and capture them
$curl = curl_init();
<code> curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//关闭证书 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT,8); $file = curl_exec($curl); curl_close($curl);</code>
When I make up an address randomly and the domain name exceeds 7 characters, for example: http://www.ffafffe.com/up358.jpg
The resulting $file is printed as:
string(686) "
Why, is there any solution
$curl = curl_init();
<code> curl_setopt($curl, CURLOPT_URL, $url); curl_setopt($curl, CURLOPT_HEADER, 0); curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);//关闭证书 curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_TIMEOUT,8); $file = curl_exec($curl); curl_close($curl);</code>
When I make up an address randomly and the domain name exceeds 7 characters, for example: http://www.ffafffe.com/up358.jpg
The resulting $file is printed as:
string(686) "
Why, is there any solution
Check the content-type of the response header. If it is image/*, it is basically an image. Some sites will return a default image to you, but this is another problem