Home  >  Article  >  Backend Development  >  Determine the existence of remote images and capture them

Determine the existence of remote images and capture them

WBOY
WBOYOriginal
2016-07-06 13:52:051036browse

$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

Reply content:

$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

Statement:
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