Determine the existence of remote images and capture them

WBOY
Release: 2016-07-06 13:52:05
Original
1041 people have browsed it

$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>
Copy after login
Copy after login

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>
Copy after login
Copy after login

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

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template