curl-and-php
Re: Set filename in POST
Date: Wed, 28 Mar 2007 09:15:42 +0200
Thanks for your response.
If I use:
curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' => '@archivename.tar.gz','filename' => 'realname.tar.gz'));
This will transmit the file archivename.tar.gz and a second parameter filename which content the string realname.tar.gz
(if I well understood curl_setopt)
But I would to transmit the content of the file archivename.tar.gz with realname.tar.gz as name of the file, like the following command line:
curl -F 'file=@archivename.tar.gz;filename=realname.tar.gz' http://servername.com
Any idea?
Pierre
Tijnema ! a écrit :
> On 3/27/07, PPCM <ppcm_at_ifrance.com> wrote:
>
>> Hello there,
>>
>> The background:
>> I need to send files to a server using a POST form.
>> But my files are not stored with their real names but with their archine
>> names.
>> I need to send files throw their real names.
>>
>> Using cURL (command line)
>> I succeed to send files with curl using a different name for the upload
>> file than the name stored on the disk:
>>
>> curl -F 'file=@archivename.tar.gz;filename=realname.tar.gz'
>> http://servername.com
>>
>> Using libcurl
>> But I can't do the same thing with libcurl, here is the code:
>>
>> $ch = curl_init();
>> curl_setopt($ch, CURLOPT_URL, http://servername.com);
>> curl_setopt($ch, CURLOPT_POST, 1);
>> curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' =>
>> '@archivename.tar.gz;filename=realname.tar.gz'));
>> $postResult = curl_exec($ch);
>> curl_close($ch);
>>
>> I have the following error:
>> failed creating formpost data
>>
>> And I can't find a solution...
>> (It should be better if I don't use the shell_exec function)
>>
>> Does somebody have an idea how to solve my problem?
>>
>> Thanks
>>
>> Pierre
>>
>
> Hi Pierre,
>
> I'm not sure, but i think you made a little fault using the quotes, try this:
>
> curl_setopt($ch, CURLOPT_POSTFIELDS, array('file' =>
> '@archivename.tar.gz','filename' => 'realname.tar.gz'));
>
> Tijnema
>
>
>
>> _______________________________________________
>> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>>
>>
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>
>
>
>
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-03-28