Home > Backend Development > PHP Tutorial > Example of using PHP to help curl capture remote URL images (solve the problem of anti-leeching)

Example of using PHP to help curl capture remote URL images (solve the problem of anti-leeching)

巴扎黑
Release: 2016-11-09 11:33:06
Original
1456 people have browsed it

php uses curl to grab remote images, which can solve the problem of anti-leeching.

function ycimg($file,$newfile)
{
// 初始化一个 cURL 对象
$curl = curl_init(); 
// 设置你需要抓取的URL
curl_setopt($curl, CURLOPT_URL, $file);
// 设置header
curl_setopt($curl, CURLOPT_HEADER, 0);
// 设置cURL 参数,要求结果保存到字符串中还是输出到屏幕上。
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// 运行cURL,请求网页
$data = curl_exec($curl);
// 关闭URL请求
curl_close($curl);
//写入获得的数据
$write = @fopen($newfile,"w");
fwrite($write,$data);
fclose($write);
return TRUE;
}
Copy after login


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