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

curl-and-php

Re: problem posting a file with curl

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Wed, 19 Jun 2002 11:56:41 +0200 (MET DST)

On Wed, 19 Jun 2002 fabian.grzeszeyk_at_alti.lu wrote:

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

Allow me to take a few trembling steps out on this thin ice. I am not a PHP
hacker.

> //---- 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);

I take it that this loads the full binary file into the $strFile variable.

> $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);

CURLOPT_BINARYTRANSFER actually changes how data is received, not sent. If I
understand things correct.

> curl_setopt($ch, CURLOPT_POST, 1);
> curl_setopt($ch, CURLOPT_POSTFIELDS, "strFile=".$strFile);

Normal HTTP POSTs are done with the contents being URL encoded. This is not.

> 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);

How do you get the file into the $strFile variable on the server side? Won't
it assume URL encoding?

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
----------------------------------------------------------------------------
                   Bringing you mounds of caffeinated joy
                   >>>     http://thinkgeek.com/sf    <<<
Received on 2002-06-19