There:
$imagespath = $IMAGES->item(0)->nodeValue;
You get the contents of the <description> in the $imagespath variable.
This variable, therefore, does not contain a DOMElement and no object type, but some string content.
Then you try to call the getAttribute() method for this variable:
$image = $imagespath->getAttribute('src');
But since $imagespath not an object (this is a string), you get Fatal Error.
If you want to get the src attribute of a tag, I suppose you should get it something like this:
$image = $IMAGES->item(0)->getAttribute('src');
i.e. reading the src node attribute returned by your XPath request - of course, before calling getAttribute() you should verify that there is actually an element returned by the request.
Also, if you want to upload images, perhaps you should get the <img> tags:
$IMAGES = $post->getElementsByTagName( "img" );
And not a <description> unit?
Pascal martin
source share