Jump to content

automating rss enclosure creation in php


bullchina

Recommended Posts

I am creating a small script to output news info from a database into rss format, and I want the ability to include enclosures, but I want it to be as easy as possible for any person to update the database. the enclosure item in an rss feed requires a url, the length in bytes of the file, and the filetype.

I am using the filesize() function to get the bytes, so the user doesn't have to input that element into the database, but is there a more automated way of adding the file type attribute, without creating a huge switch statement? I can't seem to find anything about this, but I also don't really know what terms to search for. I suppose the switch statement won't be that big, but I thought there may be a better way to automate this process.

Thanks for your help,
dave
Link to comment
https://forums.phpfreaks.com/topic/21249-automating-rss-enclosure-creation-in-php/
Share on other sites

ok, i found something called finfo_open(FILEINFO_MIME); which is supposed to give back the mime type (i forgot that word...).

i guess you have to have a pear fileinfo module installed to get that to work.

also, i found that the filesize function will not work with absolute http url's. it must be a local file.

then i saw that readfile() will return the number of bytes of any file, but that seems a little inefficient. I think it's a better idea for me to store the local path to the file relative to the site root in the database, and then appen the doc_root upon outputting the rss...

is that right, or is there a better way?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.