Jump to content


Photo

fwrite error


  • Please log in to reply
2 replies to this topic

#1 jmif96

jmif96
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 31 May 2006 - 12:42 AM

I've created a small php script that writes info for a podcast to a database, then, when a differen't is pressed, it creates an XML file for that. I do this by opening an SML file with the w attribute. However, I always the error statement in my if/else test when I run it. I cant seem to figure out why. I've give the file 777 permissions also.

Heres the part that writes the XML:

function compilePodcastXML() { 
mysqlConnect(); 

// open file 
$xmlfile = fopen ('podcasts/podcast.xml', "w"); 

// select SQL records 
$sql = "SELECT * FROM podcasts"; 
$result = mysql_query($sql); 
$num = mysql_num_rows($result); 
$podcast = mysql_fetch_array($result); 

// Write first, static part of XML File 
$date = date("D, M d Y H:i:s O"); 
$xml = "<?xml version="1.0\" encoding=\"UTF-8\"?> 
<rss xmlns:itunes=\"http://www.itunes.com/dtds/podcast-1.0.dtd\" version=\"2.0\"> 
   
  <channel> 

    <title>xxx</title> 
    <description>xxxdescription> 
    <link>xxx</link> 
    <language>en-us</language> 
    <copyright>xxx</copyright> 
    <lastBuildDate>$date</lastBuildDate> 
    <pubDate>$date</pubDate> 
    <docs>xxx</docs> 
    <webMaster>xxx</webMaster> 

    <itunes:author>xxx</itunes:author> 
    <itunes:subtitle>xxxitunes:subtitle> 
    <itunes:summary>xxx</itunes:summary> 

    <itunes:owner> 
           <itunes:name>xxx</itunes:name> 
           <itunes:email>xxx</itunes:email> 
    </itunes:owner> 

     
    <itunes:category text=\"Transportation\"> 
         <itunes:category text=\"Podcasting\" /> 
    </itunes:category> "; // END STATIC XML 
     
// write item statements 
for ($i = 0; $i < $num; $i++) { 

$xml .= " 
    <item> 
        <title>".$podcast['title'][$i]."</title> 
        <link>".$podcast['infolink'][$i]."</link> 
        <guid>".$podcast['mp3url'][$i]."</guid> 
        <description>".$podcast['description'][$i]."</description> 
        <enclosure url=\"".$podcast['mp3url'][$i]."\" length=\"".$podcasts['filesize'][$i]."\" type=\"audio/mp3\" /> 
        <category>Podcasts</category> 
        <pubDate>".date("D, M d Y H:i:s O", $podcast['pubdate'][$i])."</pubDate> 
         
        <itunes:author>DVA CRJ Team</itunes:author> 
         
        <itunes:subtitle>".$podcast['Isubtitle'][$i]."</itunes:subtitle> 
        <itunes:summary>".$podcast['Isummary'][$i]."</itunes:summary> 
        <itunes:duration>".$podcast['Iduration'][$i]."</itunes:duration> 
        <itunes:keywords>".$podcast['Ikeywords'][$i]."</itunes:keywords> 
         
    </item> 
    "; 
} 

// finish up xml file 
$xml .= "  </channel> 

</rss>"; 

if (fwrite ($xmlfile, $sml)) { 
print ("Podcast XML file created successfully."); 
$doneBy = $_SESSION['f_name'].' '.$_SESSION['l_name']; 
$date = time(); 
$query = "INSERT INTO adminLog VALUES ('','Podcast','Publish','$doneBy','$title','$date')"; 
mysql_query($query); 
} else { 
print ("Error creating XML file."); 
} 

?> 


Any ideas?

Thanks!

#2 poirot

poirot
  • Members
  • PipPipPip
  • Advanced Member
  • 646 posts
  • LocationAustin, TX

Posted 31 May 2006 - 02:51 AM

Well, I don't know what happens when you try to use an undefined variable as 2nd argument for fwrite, but that may be your problem:
if (fwrite ($xmlfile, $sml)) {
Shouldn't it be:
if (fwrite ($xmlfile, $xml)) {

?
~ D Kuang

#3 jmif96

jmif96
  • New Members
  • Pip
  • Newbie
  • 6 posts

Posted 31 May 2006 - 07:37 PM

Yup that's correct, I hate it when I miss little things like that. However, now I have a differen't problem, when it prints the <item> tags to the xml file it dosen't print the whole string from the database. It prints this:

<item>
        <title>t</title>
        <link>h</link>
        <guid>h</guid>
        <description>t</description>
        <enclosure url="h" length="" type="audio/mp3" />
        <category>Podcasts</category>
        <pubDate>Wed, Dec 31 1969 17:00:01 -0700</pubDate>
        
        <itunes:author>DVA CRJ Team</itunes:author>
        
        <itunes:subtitle>t</itunes:subtitle>
        <itunes:summary>t</itunes:summary>
        <itunes:duration>t</itunes:duration>
        <itunes:keywords>k</itunes:keywords>
        
    </item>

I cannot seem to find why it's only printing that. I've checked the databases and there is no problem there. Any ideas?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users