I’m using PHP to create my feed. If my feed is reading straight from the PHP script (i.e. http://…feed.php), I just include this in my PHP script
header(“Content-type: application/json”);
and echo my array using json_encode().
However, for several reasons, I don’t want to use the PHP script as the feed. I want PHP to create a static JSON file, and then use that file as the feed. I am able to write the file, it looks like a well formed JSON object, but I get this error below.
If anyone knows of a good trick please let me know.
The server returned an unsupported content type. Was expecting ‘application/rss+xml’, ‘text/xml’, ‘application/xml’ or ‘application/json’ but received ‘text/plain’.
If your hosting service provides you cpanel access go into apache mime types and add the mime type: application/json with the extension: json
If you don’t have cpanel access you can add the following to your .htaccess file:
AddType application/json json
Ok, sounds “easy” enough. Do I need to name the file with a certain extension (i.e. .json) in order for it to get the header?
It will need a .json extension
Well as it turns out, it was already a mime type, I just needed to name my static files as .json! Im guessing .json is pretty standard.
My main reason for doing this, is so that multiple channel viewers will not put a strain on the database. Also if the database every goes down, the static file is set.
For anyone using PHP, it’s a piece of cake
$json_data = json_encode($JSON2);
All I did was replace
echo json_encode($JSON2);
with
file_put_contents('…/output.json, $json_data);
note: the ‘user’ on your server that your webserver / php shows up as will need permission to write to the directory on which you place this.