【发布时间】:2015-03-09 14:09:26
【问题描述】:
我需要下载超过 100.000 张图片。图片有:.png、.jpg、.jpeg、.gif 格式。 我有权使用这些图片。他们为我提供了一个包含所有 url 的 XML 文件
网址有结构
其他域/productimages/code/imagename.jpg/.png/.gif
我有一个名为$codes[]的php数组中的所有代码
我还有数组$images[]上所有图像的完整路径@
我需要下载所有这些图片并保持相同的结构
mydomain/productimages/code/imagename.jpg/.png/.gif
到目前为止,我通过互联网进行的研究是:
遍历所有页面(每个酒店代码)
$i = 1;
$r = 100000;
while ($i < $r) {
$html = get_data('http://otherdomain.com/productimages/'.$codes[$i].'/');
getImages($html);
$codes[$i++];
}
function getImages($html) {
$matches = array();
$regex = '~http://otherdomain.com/productimages/(.*?)\.jpg~i';
preg_match_all($regex, $html, $matches);
foreach ($matches[1] as $img) {
saveImg($img);
}
}
function saveImg($name) {
$url = 'http://otherdomain.com/productimages/'.$name.'.jpg';
$data = get_data($url);
file_put_contents('photos/'.$name.'.jpg', $data);
}
你能帮我解决这个问题吗,因为脚本根本不起作用
【问题讨论】:
-
尝试使用 file_get_contents 而不是 get_data
-
仍然没有效果@flyingeagle413