I'm a little stuck attempting to prepend this document with PHP. Please see below for the code itself.
<?php
if(isset($_POST['inputTitle']) && isset($_POST['inputDate']) && isset($_POST['inputLink'])) {
$data = "<item>" . "\r\n" . "<title>" . $_POST['inputTitle'] . "</title>" . "\r\n" . "<description>" . $_POST['inputDate'] . "</description>" . "\r\n" . "<link>" . $_POST['inputLink'] . "</link>" . "\r\n" . "</item>" . "\r\n" . "\r\n";
$ret = file_put_contents('filename.rss', $data, FILE_APPEND | LOCK_EX);
if($ret === false) {
die('There was an error writing this file');
}
else {
echo "<b>Thank you for adding a news item.</b> <br />";
echo "If this news item does not appear on the application, please contact IT Support including a screenshot of this webpage. <br />";
echo "<br />";
echo "<br />";
echo "###################### <br />";
echo "$ret bytes written to file. <br />";
echo "###################### <br />";
}
}
else {
die('no post data to process');
}
?>
This code currently works for writing to the bottom of a file, but I'd like to add to the top of it.
I'm essentially creating an RSS feed manually, and with my iOS application it sorts them from top to bottom as it reads them.