Help - Search - Members - Calendar
Full Version: Rss Create Script Errors
Invision Power Services > Community Forums > Community Web Design and Coding
Shmohel
I posted this over at: http://webdeveloper.com/forum/showthread.php?p=558464 maybe someone here can help me figure this one out.

I have a real simple script that runs some queries to generate an RSS formatted XML file. It was working perfectly fine and then all of a sudden I get this below error:

CODE
Warning: fopen(xml/rss1.xml): failed to open stream: Permission denied in /home/shmohel/public_html/rss.php on line 2

Warning: fwrite(): supplied argument is not a valid stream resource in /home/shmohel/public_html/rss.php on line 23

Warning: fclose(): supplied argument is not a valid stream resource in /home/shmohel/public_html/rss.php on line 24


Here is the entirety of the script, only about 25 lines:

CODE
<?php
$file= fopen("xml/rss1.xml", "w"); #This is line 2
$rss.='<?xml version="1.0" encoding="ISO-8859-1"?>';
$rss.="<rss version='2.0'>";
$rss.="<channel>";
$rss.="<title>10 Newest Recipes - Recipe Tavern</title>";
$rss.="<description>A list of the 10 most recently submitted recipes at the Recipe Tavern.</description>";
$rss.="<link>http://www.recipetavern.com</link>";
mysql_connect ("localhost", "*****", "*****") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("*****");
mysql_select_db ("*****");
$sql=mysql_query("SELECT r.recipeid,r.recipename,r.desc FROM *****.`recipe` AS r JOIN *****.`beer_members` AS m ON r.memberid=m.id ORDER BY dateadded desc LIMIT 10;") or die(mysql_error());
while($rec=mysql_fetch_assoc($sql)){
$rss.="<item>";
$rss.="<title>".$rec['recipename']."</title>";
$rss.="<description><![CDATA[".$rec['desc']."]]></description>";
$rss.="<link><![CDATA[http://www.recipetavern.com/index.php?pg=recipe&recipeid=".$rec['recipeid']."]]></link>";
$rss.="<guid isPermaLink='false'>recipetavern_recipeid_".$rec['recipeid']."</guid>";
$rss.="</item>";
}
$rss.="</channel>";
$rss.="</rss>";
fwrite($file, $rss); #This is line 23
fclose($file); #This is line 24
?>


I tried playing around with the permissions of the XML file and nothing seemed to work, so I don't think it is a permissioning error. Does anyone here see any blatant mistakes in this code? Am I missing something?
Digi
Is this something that is ahppening all the time now? "All of the Sudden" can mean a lot of things. Sometimes it works and occasionally you get this error?
Shmohel
By "all the time" I mean that it was working about a week ago, and the last couple days it is not. I have contact my host and they repeatedly assure me that nothing has changed blah blah (not very helpful people.) But I am not convinced of that.

I just was hoping to get someone to verify that this script looks totally legit and is not missing anything glaring. The issue is oviously that the script will not open the file.

Do you have any other suggested methods? Should I just create a script that when called outputs the RSS data (which is how I believe the IPB script works.)
Dan_merged
The permissions ( chmod ) on the file xml/rss1.xml don't allow for writing. You just need to change the permissions on the file via FTP ( or SSH ) to allow for this, this would usually mean setting it to 0777.
Shmohel
sad.gif I had already tried that. It didn't work.
bfarber
Could verify the file owner as well (most ftp apps will show you this). But if the file is already 777, owner shouldn't matter as it's globally writeable at that point...
Shmohel
I deleted the file, and ran the script allowing it to regenerate and create a new one. And poof, just like the magic, the PHP gods ran my script. I tried it a couple more times and it works fine now.

Conclusion: I guess maybe the file was corrupted somehow?
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.