curl-and-php
Re: Set filename in POST
Date: Tue, 27 Mar 2007 18:31:12 +0200
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
Received on 2007-03-27