SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php write problem

    Previous problem solved...new one here.

    i can now loop through my records, and output it into xml (for the most part). However, i need to write each row to a new file. I am having trouble with that, as I keep getting "HTTP Wrapper Errors" and FTP Errors"

    Please assist!

    PHP Code:
    <?php // output basic header info and beginning of xml tags
    $output "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

    //$output .= "<Assets>";

    $result_story mysql_query"Select story.storyid, story.created, story.startdate, story.headline, story.subhead, story.byline, story.body, story.comments, story.isactive, story.keepalive, story.fromprint, story.siteid, topic.topicname FROM story, storytopic, topic WHERE story.isactive = 'Y' AND story.storyid=storytopic.storyid AND storytopic.topicid = topic.topicid"$dbhandle );
    $totalrows mysql_num_rows($result_story);

    while(
    $row mysql_fetch_array($result_storyMYSQL_ASSOC)) {
         
    $output .= "<Asset>";
        
    $output .= "<AssetType>Story</AssetType>";
        
    $output .= "<Fields>";
              foreach(
    $row as $name=>$value){
                  
                
    $output .= "<Field>";
                
    $output .= "<Name>" .htmlentities($name);
                
    $output .= "</Name>";
                
    $output .= "<Values>";
                
    $output .= "<Value>" .htmlentities($value)."</Value>";
                
    $output .= "</Values>";
                
    $output .= "</Field>";
                
                    
              }
          
    $output .= "</Fields>";    
          
    $output .= "</Asset>";
          
    $fh=fopen("ftp://username:password@server/".$row["storyid"] .".xml","w");
        
    fwrite($fh,utf8_encode($output));
        
    fclose($fh); 
    }

    // close the connection
    mysql_close($dbhandle);
    ?>

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Because you did not say in your post that you want to upload the files to a remote FTP server, I must ask do you really want to do that? And if so, use ftp functions; otherwise save the files using a local path.
    Saul

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i tried both methods...ideally i want to save them locally. I had this working, and then all of a sudden (you know how it goes) i tweeked it, and i cant get it to work again.

    here is my code to save locally:

    PHP Code:
    $output .= "some data";    
          
    $file_name $row["storyid"] .".xml";
          
    $fh=fopen($file_name,"w");
          
    fwrite($fh,utf8_encode($output));
          
    fclose($fh);
          
    chmod($file_name,0777);
        


  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    So this is supposed to save the file in the current directory; does php have the write permissions on that directroy?
    Saul

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes to all of the above..chmod 777 for everything

  6. #6
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    84
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i got it...it was working, but for some reason was not showing up
    i rebooted my system...voila


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •