remote directory listing downloading

Create a new directory named myDir to store files and execute the following script.
<?php
$dir = 'http://www.trenatics.com/public/images/iconfile/sprites/css-sprite/';
$html = file_get_contents($dir);
if(preg_match_all('/<a href="(.+?)">(.+?)<\/a>/',$html,$matches)){
  foreach(array_keys($matches[0]) as $n) {
    $name = $matches[1][$n];
    echo '<a href="'.$dir.$name.'" download>'.$name.'</a><br/>';
$image = file_get_contents($dir.$name);
file_put_contents('myDir/'.$name, $image);
  }
}

Labels: ,

© copyright-2020 Rejaul