title: Correct Method For Adding Images To An RSS Feed?
body: <p>As in one per item, not a logo for the feed as a whole.</p>
  
  <p>I am using php to generate my feed with values from a db. Nothing shows on firefox but if I open the url in chrome I can see all the xml output there and it looks fine to me.</p>
  
  <p>One thing I am unsure about is including images, I used this website and implemented what it said:</p>
  
  <p><a href="http://twigstechtips.blogspot.com/2010/10/add-image-to-your-rss-feed-item.html" rel="nofollow noreferrer">http://twigstechtips.blogspot.com/2010/10/add-image-to-your-rss-feed-item.html</a></p>
  
  <p>I have also seen this SO question as well: <a href="https://stackoverflow.com/questions/4130406/rss-feed-to-feed-images-to-your-rss">RSS feed: to feed images to your rss</a> . This might be the best way and I assume there's a php function to determine the file size of an image?</p>
  
  <p>The most common way I have seen is also a question on SO: <a href="https://stackoverflow.com/questions/483675/images-in-rss-feed">Images in RSS feed</a></p>
  
  <p>I have tried validating the feed to test why it doesn't show on firefox but because it is so large no website I've visited so far can validate it. Is it possible that this is why it doesn't show on Firefox (it did used to at some point when I truncated the <code>CDATA</code> section and before I tried to add images).</p>
  
  <p>The only thing is I am unsure where it goes in my feed. Please see source code and example output below:</p>
  
  <p><strong>Source</strong> (minus unnecessary things like includes etc)</p>
  
  <pre><code>header("Content-Type: application/rss+xml; charset=utf-8");
  
  $rssfeed = '&lt;?xml version="1.0" encoding="UTF-8"?&gt;' . "\n";
  $rssfeed .= '&lt;rss version="2.0"&gt;' . "\n";
  $rssfeed .= '&lt;channel&gt;' . "\n";
  $rssfeed .= '&lt;title&gt;RSS feed&lt;/title&gt;' . "\n";
  $rssfeed .= '&lt;link&gt;http://www.website.co.uk&lt;/link&gt;' . "\n";
  $rssfeed .= '&lt;description&gt;RSS feed from www.website.co.uk&lt;/description&gt;' . "\n";
  $rssfeed .= '&lt;language&gt;en-uk&lt;/language&gt;' . "\n";
  $rssfeed .= '&lt;copyright&gt;Copyright (C) 2011 website.co.uk&lt;/copyright&gt;' . "\n\n";
  
  $query = 'SELECT * 
            FROM uk_newsreach_article t1
                INNER JOIN uk_newsreach_article_photo t2
                    ON t1.id = t2.newsArticleID
                INNER JOIN uk_newsreach_photo t3
                    ON t2.newsPhotoID = t3.id
            ORDER BY t1.publishDate DESC;';
  
  $result = mysql_query($query) or die ("Could not execute query");
  
  
  while($row = mysql_fetch_array($result)) {
      extract($row);
  
      $rssfeed .= '&lt;item&gt;' . "\n\t";
      $rssfeed .= '&lt;title&gt;' . $row['headline'] . '&lt;/title&gt;' . "\n\t";
  
      $link= 'http://www.website.co.uk';
      $url = ' . $link . '/' . $row['newsArticleID'];
  
      $rssfeed .= '&lt;link&gt;' . $url . '&lt;/link&gt;' . "\n\t";
      $rssfeed .= '&lt;guid&gt;' . $url . '&lt;/guid&gt;' . "\n\t";
  
      $text = $row['text'];
      $rssfeed .= '&lt;description&gt;&lt;![CDATA[' . $text . ']]&gt;&lt;/description&gt;' . "\n\t";
      // $rssfeed .= '&lt;description&gt;' . htmlentities($text) . '&lt;/description&gt;' . "\n\t";
  
      // add image
      $rssfeed .= '&lt;media:thumbnail url="' . $row['mediumURL'] . '" height="' . $row['mediumHeight'] . '" width="' . $row['mediumWidth'] . '" /&gt;'. "\n\t";
  
      $rssfeed .= '&lt;pubDate&gt;' . date("D, d M Y H:i:s O", strtotime($row['publishDate'])) . '&lt;/pubDate&gt;' . "\n";
      $rssfeed .= '&lt;/item&gt;' . "\n\n";
  }
  
  $rssfeed .= '&lt;/channel&gt;' . "\n";
  $rssfeed .= '&lt;/rss&gt;' . "\n";
  
  echo $rssfeed;
  </code></pre>
  
  <p><strong>Example Output</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;rss version="2.0"&gt;
  &lt;channel&gt;
  &lt;title&gt;RSS feed&lt;/title&gt;
  &lt;link&gt;http://www.website.co.uk&lt;/link&gt;
  &lt;description&gt;RSS feed from www.website.co.uk&lt;/description&gt;
  &lt;language&gt;en-uk&lt;/language&gt;
  &lt;copyright&gt;Copyright (C) 2011 website.co.uk&lt;/copyright&gt;
  
  &lt;item&gt;
  &lt;title&gt;Some Title&lt;/title&gt;
  &lt;link&gt;http://www.website.co.uk/news/articles/slug&lt;/link&gt;
  &lt;guid&gt;http://www.website.co.uk/news/articles/slug&lt;/guid&gt;
  &lt;description&gt;&lt;![CDATA[&lt;p&gt;Text&lt;/p&gt;
  &lt;p&gt;More text&lt;/p&gt;
  &lt;p&gt;Posted by Firstname Lastname&lt;/p&gt;]]&gt;&lt;/description&gt;
  &lt;media:thumbnail url="http://www.website.co.uk/img/image.jpg" height="300" width="203" /&gt;
  &lt;pubDate&gt;Mon, 03 Oct 2011 16:57:09 +0000&lt;/pubDate&gt;
  &lt;/item&gt;
  ....
  ....
  &lt;/channel&gt;
  &lt;/rss&gt;
  </code></pre>