Php 从html下载图像并保留文件夹结构

Php 从html下载图像并保留文件夹结构,php,regex,image,Php,Regex,Image,我需要下载超过10万张图片。图片有:.png、.jpg、.jpeg、.gif格式。 我有权使用那些照片。他们为我提供了一个包含所有url的XML文件 url具有以下结构: otherdomain/productimages/code/imagename.jpg/.png/.gif 我有一个名为$codes[]php数组中的所有代码 我还拥有阵列上所有图像的完整路径$images[] 我需要下载所有这些图片并保持相同的结构 mydomain/productimages/code/imagename

我需要下载超过10万张图片。图片有:.png、.jpg、.jpeg、.gif格式。 我有权使用那些照片。他们为我提供了一个包含所有url的XML文件

url具有以下结构:

otherdomain/productimages/code/imagename.jpg/.png/.gif

我有一个名为
$codes[]
php数组中的所有代码 我还拥有阵列上所有图像的完整路径
$images[]

我需要下载所有这些图片并保持相同的结构

mydomain/productimages/code/imagename.jpg/.png/.gif

到目前为止,我在互联网上的研究成果是:

在所有页面上循环(每个酒店代码)

$i=1;
$r=100000;
而($i<$r){
$html=获取数据($html)http://otherdomain.com/productimages/“.$code[$i]./”);
getImages($html);
$code[$i++];
}
函数getImages($html){
$matches=array();
$regex='1~http://otherdomain.com/productimages/(**?\.jpg~i';
preg_match_all($regex,$html,$matches);
foreach($img与[1]匹配){
储蓄人民币($img);
}
}
函数saveImg($name){
$url='1http://otherdomain.com/productimages/“.$name.”.jpg“;
$data=获取数据($url);
文件内容('photos/'.$name.'.jpg',$data);
}

你能帮我完成这个任务吗?因为脚本根本不起作用。我可以建议你更简单、更快地完成任务。 将完整的URL写入list.txt
执行wget-x-i list.txt命令,该命令将下载所有图像,并根据站点结构将它们放在适当的目录中。

我可能会建议您更简单、更快地完成任务。 将完整的URL写入list.txt
执行wget-x-i list.txt命令,该命令将下载所有图像,并根据站点结构将它们放在适当的目录中。

尝试使用file_get_内容而不是get_数据直到无效@flyingeagle413尝试使用file_get_内容而不是get_数据直到无效@flyingeagle413它工作得非常好,是否碰巧知道我是否可以将wget设置为将所有文件下载到某个位置(例如HTTP根文件夹)?它工作得很好,是否碰巧知道我是否可以将wget设置为将所有文件下载到某个位置(例如HTTP根文件夹)?
   $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);
    }