PHP采集图片列子。
<p>1. 使用file_get_contents()函数:</p>
<pre class="lang-php prettyprint-override"><code><?php
$imgUrl = 'http://example.com/images/foo.png'; // 需要采集的图片URL
$imgData = file_get_contents($imgUrl); // 读取图片文件内容
file_put_contents('/path/to/save/foo.png', $imgData); // 保存图片到本地
?>
</code></pre>
<p>2. 使用cURL函数:</p>
<pre class="lang-php prettyprint-override"><code><?php
$imgUrl = 'http://example.com/images/foo.png';
$ch = curl_init($imgUrl);
$fp = fopen('/path/to/save/foo.png', 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
?>
</code></pre>
PHP采集图片列子。