cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

problem posting a file with curl

From: <fabian.grzeszeyk_at_alti.lu>
Date: Wed, 19 Jun 2002 11:14:23 +0200

Hi there,

  I have some problem with the curl library for posting a zip file.

  How can I upload a zip file on a distant server, I try the follwing
script:

on local machine:

      //---- Get file content in binary mode
      $fileSize = filesize($EXPORT_LOCAL_PATH."
\\".$EXPORT_FILENAME.".bz2");
      $fp = fopen($EXPORT_LOCAL_PATH."\\".$EXPORT_FILENAME.".bz2", "rb");
      $strFile = fread($fp, $fileSize);
      fclose($fp);

      //---- Call remote page and post file
      $ch = curl_init("$remotePath");
      if (!$ch)
            die( "Cannot allocate a new PHP-CURL handle" );

      //----We'll be returning this transfer, and the data is binary , so
we don't want to NULL terminate
      curl_setopt($ch, CURLOPT_USERPWD,"$HTTPS_USER:$HTTPS_PWD");
      curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
      curl_setopt($ch, CURLOPT_POST, 1);
      curl_setopt($ch, CURLOPT_POSTFIELDS, "strFile=".$strFile);

      //----Grab the page and save the contents in the $contents variable
      $contents = curl_exec($ch);

      //----Close the connection
      curl_close($ch);

      //----Print contents selection
      print "
---------------------------------------------------------------------------------------------------------------------------<br>";
      print "remote results: <br>";
      print_r($contents);

I call an other page on the remote server to unzip the file in the post:

      //---- Create bzip2 file
      $fp = fopen($FILEPATH."file.bz2", "wb");
      fwrite($fp, $strFile);
      fclose($fp);

      //---- Bunzip2 file
      exec($BUNZIP_PATH."bunzip2 file.bz2");

--------------------------------------------------------------------------------------------------------------------------------------------------------------
On local machine, the zip file can be dezipped but after the post on the
remote server, data is corrupted.

Is there an other solution to post a file or how can I modify this script
to get it works ?

Please help me.

Thanks in advance.

 Fabian GRZESZEYK
 Web developer

----------------------------------------------------------------------------
                   Bringing you mounds of caffeinated joy
>>> http://thinkgeek.com/sf <<<
Received on 2002-06-19