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

curl-and-php

Re: problem posting a file with curl

From: Pete James <peter_james_at_advanis.ca>
Date: Wed, 19 Jun 2002 07:54:23 -0600

No. You don't want to get the contents of the file into a string...
leave the file as is, in it's temp location. Specify the filename
(prefixed with an @ sign) to postvars in an array, like so:

curl_setopt($ch, CURLOPT_POSTFIELDS, "filename=>@$tempfile");

You don't need the BINARYTRANSFER option (I'm not even sure what this
does).

See my example at:

http://curl.haxx.se/libcurl/php/examples/?ex=multipartpost.php

P.

fabian.grzeszeyk_at_alti.lu wrote:
>
> By posting the data to the remote page on the server side with the curl
> option:
>
> -->curl_setopt($ch, CURLOPT_POSTFIELDS, "strFile=".$strFile);
>
> The $strFile var contain the file data coming from the post.
>
> I don't think curl assume the url encoding but I try to use the PHP
> urlencode function to encrypt post but data is always corrupted
>
> Fabian GRZESZEYK
> Web developer
> ___________________________________________
> ALTI | Consulting, IT & Extended Web Solutions
> Member of the Alti Group ( http://www.alti.com)
>
> 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 <<<

----------------------------------------------------------------------------
                   Bringing you mounds of caffeinated joy
>>> http://thinkgeek.com/sf <<<

Received on 2002-06-19