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

curl-and-php

Re: PHP - Curl and Multipart Form File Upload

From: Andrey Kuznetsov <kandrey89_at_gmail.com>
Date: Sat, 22 Nov 2008 21:13:53 -0800

Thanks but I figured out with help from IRC how it should work, the
problem was with pointing to the file on windows system, for some
reason relative path was not recognized, so I had to type in the whole
path:

<?php

$data = array
(
                'type' => 'direct',
                'userfile[]' => '@c:\Apache Server Doc Folder\picture.jpg',
                'private' => '0',
);

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://www.url.com/upload.php");
curl_setopt($curl, CURLOPT_VERBOSE, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
curl_close($curl);

?>

On Sat, Nov 22, 2008 at 1:39 PM, Daniel Stenberg <daniel_at_haxx.se> wrote:
> On Thu, 20 Nov 2008, Andrey Kuznetsov wrote:
>
>> curl_setopt($docurl, CURLOPT_POSTFIELDS,
>> array("userfile"=>"{@picture.JPG}"));
>> $webpage = curl_exec($docurl);
>
> AFAIK, the magic key here is to let the name start literally with a '@' and
> the rest being a file name. Staring it with '{' will just make that string
> be included as text.
>
> See the example here:
>
> http://curl.haxx.se/libcurl/php/examples/multipartpost.html
>
> --
>
> / daniel.haxx.se
> _______________________________________________
> http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
>

-- 
Remember The Past, Live The Present, Change The Future
Those who look only to the past or the present are certain to miss the
future [JFK]
kandrey89@gmail.com - http://kandrey89.dyndns.dk
Live Long and Prosper,
Andrey
_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2008-11-23