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
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?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.