Hello,
I want to build a php form that would upload and unzip a folder that contains some static html files and a shared image folder. This part is done. Next, I need to compare the img src in the html files with the images in the image folder. If images exist don't do anything, else save unused images in a temp folder or delete.
Here's my code. I can extract images from the shared image folder and the relative image src path from the html files but I don't know how to compare/check the two. Do I check the html file against the image folder or the other way around? Not sure what PHP functions to use(file_exist, getimagesize, curl, etc.). Please help.
//path to directory to scan
$dir = "path/to/image/directory";
//get all image files with a .jpg, .gif, .png extension.
$images = glob($dir . "*.{jpg,gif,png}", GLOB_BRACE);
//print images in image folder - for testing purpose spits out images/1.jpg, images/2.png, images/3.gif
foreach($images as $image)
{
echo 'images/'. basename($image) . '<br />';
}
//extract img src from html
$url="path/to/html";
$html = file_get_contents($url);
$dom = new DOMDocument();
$dom->loadHTML($html);
//echo image src - for testing purpose spits out images/1.jpg, images/2.png, images/3.gif
foreach ($dom->getElementsByTagName('img') as $img) {
echo $img->getAttribute('src'). '<br />';
}

