...
} else if($imageTags->hasAttributes() == false){
header("Location: index.php");
die; // needed here to prevent code below, if any from executing
}
...
also on your edit note about removing iframe and getting error, you need to check if $doc->getElementsByTagName('iframe')
has actually grabbed anything, example:
$imageTags = $doc->getElementsByTagName('iframe')
if ($imageTags->length > 0) {
$imageTags = $imageTags->item(0);
...