PHP FTP cURL Cross-Server RSS Mess lol... need help

Discussion in 'Programming' started by mm-93, Sep 7, 2008.

  1. #1
    Hello all... I am having a time with trying to get my cross-server, CMS/RSS feature working.

    Basically, I need to write to a simple file on a different server... I know I can't use PHP fopen/fput over http to write a file, but I have researched and found some PHP/cURL and PHP/FTP code but I still haven't been able to make it work.

    Does anyone know how to do this? Here is the current code I am working with:


    $file = "http://".$url."/rss_holder.php";
     
    $c = curl_init();
    curl_setopt($c, CURLOPT_URL, "http://".$url."/rss_holder.php");
    curl_setopt($c, CURLOPT_USERPWD, "user:pass");
    curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($c, CURLOPT_PUT, true);
    curl_setopt($c, CURLOPT_INFILESIZE, filesize($file));
     
    $fp = fopen($file, "r");
    curl_setopt($c, CURLOPT_INFILE, $fp);
     
    curl_exec($c);
     
    curl_close($c);
    fclose($fp); 
    Code (markup):

    As you can see with this code, I am trying to write to a file (on a separate server) the RSS Feeds code by looping through a record set from MySQL:


       $curl = curl_init();
        $fp = fopen("http://www".$url."/rss_holder.php", "w");
    
      while($row2=mysql_fetch_array($result2))
      	{
    		$fp = "if($q==".$row2['id'].")\n";
    		$fp .= "{\n";
    		$fp .= "$xml=(".$row2['feed_url'].")\n";
    		$fp .= "}\n";
    }
        curl_setopt($curl, CURLOPT_FILE, $fp);
    
        curl_exec ($curl);
        curl_close ($curl);
    Code (markup):

    I am getting errors like:

    failed to open stream: HTTP wrapper does not support writeable connections in etc....

    So I know you will probably look at this and instantly see what's wrong. I really appreciate you taking the time to post a solution or any advice. Thanks!
    Mitch
     
    mm-93, Sep 7, 2008 IP
  2. mm-93

    mm-93 Peon

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I figured things out... here's what I ended up using:


    $contents = "This is a test file\nTesting 1,2,3..";
    		
    $tempHandle = fopen('php://temp', 'r+');
    fwrite($tempHandle, $contents);
    rewind($tempHandle);        
     			
    $conn = ftp_connect("ftp.server.com") or die("Could not connect");
    ftp_login($conn,"user","pass");
    echo ftp_fput($conn,"/someurl.com/target.txt",$tempHandle,FTP_ASCII);
    ftp_close($conn);
    Code (markup):
    Works excellent... ;)
     
    mm-93, Sep 7, 2008 IP