Images Download by passing website url

$siteurl = 'http://www.example.com/'; // site Url
$dom = new DOMDocument();
$html = file_get_contents($siteurl);
$dom->loadHTML($html);
$dom->preserveWhiteSpace = false;
$images = $dom->getElementsByTagName('img');
foreach($images as $img)
{
$url = $img->getAttribute('src');
//$alt = $img->getAttribute('alt');
//echo "$url";
$image_data = file_get_contents($url); // get content from url..
$image_name = basename($url); // for save same name which in url.
$image__save_location = ""; // Save location or path..
$ext = pathinfo($url, PATHINFO_EXTENSION); // Check Extensions
if($image_data && $ext!='')
{
file_put_contents($image__save_location."/".$image_name, $image_data);
echo 'Download Success --'.$image_name;
}
}
?>

Leave a Reply

Your email address will not be published. Required fields are marked *