download images directly to your local computer, without the need for any authentication, permission, etc.
<?php
$url=’https://www.example.com/index.php’;
$urlsrc=’https://www.example.com/’;
$doc=new DOMDocument();
$html=file_get_contents($url);
@$doc->loadHTML($html);
$xml=simplexml_import_dom($doc); // just to make xpath more simple
$images=$xml->xpath(‘//img’);
$filenum=1;
$Successful=0;
$Failed=0;
foreach ($images as $img)
{
$url_components = parse_url($img[‘src’]); // First parse the URL
$url_path = $url_components[‘path’]; // Then get the path component
$ext = pathinfo($url_path, PATHINFO_EXTENSION); // Then use pathinfo()
if($img[‘title’]!=null)
{
$imgtitle=$img[‘title’];
}
else
{
$imgtitle=pathinfo($url_path, PATHINFO_FILENAME);
}
if (strpos($img[‘src’],’http’) !== false)
{
$chkcopy=@copy($img[‘src’], ‘images_extract/data/’.$imgtitle.’.’.$ext);
if($chkcopy)
{
echo $filenum.’) ‘.$img[‘src’].'<br>’;
$Successful++;
}
else
{
echo $filenum.’) ‘.$img[‘src’].'<br>’;
$Failed++;
}
}
else
{
$chkcopy=@copy($urlsrc.$img[‘src’], ‘images_extract/data/’.$imgtitle.’.’.$ext);
if($chkcopy)
{
echo $filenum.’) ‘.$urlsrc.$img[‘src’].'<br>’;
$Successful++;
}
else
{
echo $filenum.’) ‘.$urlsrc.$img[‘src’].'<br>’;
$Failed++;
}
}
$filenum++;
}
$Total=$filenum-1;
echo ‘Total Count: ‘.$Total.'<br>’;
echo ‘Successful Count: ‘.$Successful.'<br>’;
echo ‘Failed Count: ‘.$Failed.'<br>’;
?>