XML Image and Video Sitemap Creator

Create a SiteMap with PHP

★  xml_image_and_video_sitemap_creator.zip  

The XML Image & Video Sitemap Creator class allows you to create specific sitemaps for image, video and other content. The sitemap contains additional <image> and <video> tags which are used by Google to improve the indexing performance of images and videos on a website.

This class will crawl through an entire directory and subdirectory structure to index image and video files as configured in the configuration options of the class. It can also index other files by providing their specific file extensions.

The landing page <loc> for a specific image or video will automatically be determined by the class by checking if one of the landing pages; like ‘index.php’ (as configured in the configuration options of the class) is present in the crawled directory. When not present the main landing page will be used.


The most simple example which indexes the entire directory and subdirectory structure from the current working directory and writes it to a file:

$xml = new xmlsitemap;
$filecontent = $xml -> createsitemap();
if ($fp = fopen('sitemap.xml', 'wb')) {
 fwrite($fp, utf8_encode($filecontent));

API Reference

// Create a new instance of the class
$xml = new xmlsitemap;
$xml -> XMLURL          = 'http://www.test.com'; // Specify the URL instead of auto-determining it
$xml -> Excludedir      = array('thumbs', '_vti_cnf'); // Exclude specific directories from indexing
$xml -> Excludehtaccess = true; // Exclude directories with a .htaccess file from indexing
$xml -> XMLimages       = array('gif', 'png'); // Index these specific images (extensions) only
$xml -> XMLvideos       = array('vob', 'wmv'); // Index these specific movies (extensions) only
$xml -> XMLothers       = array('htm', 'html'); // Index these other non image & video file extensions also
$xml -> XMLlandingpages = array('index.html','index.htm','index.php'); // Use these landing pages when found with the indexed files
$xml -> Mainlandingpage = 'index.asp'; // Set the main landing page if no other landing page can be found
$xml -> createsitemap([serverpath]); // The function which returns the XML code, indexes the path provided or current working directory
$xml -> results(); // Returns the statistics as an array with keys "videos", "images" and others"

An example script which is self explanatory is included with the class.

★  xml_image_and_video_sitemap_creator.zip