cURL / Mailing Lists / curl-library / Single Mail

curl-library

Uploading a file via HTTP Post

From: Carter R. Harrison <carterharrison_at_mac.com>
Date: Sat, 30 Jun 2007 14:21:08 -0400

I've been struggling with this for a while now and I just can't seem
to make this work... I want to upload a file (in this case a .torrent
file) to a php web application. I can upload it via CURL on the
command line by typing the following:

curl -F upload_file=@filename.torrent http://localhost/index.php

now I'm trying to translate that line into the appropriate calls to
libcurl. Here's what I have.. The result is that CURL makes the
post, but my file is never uploaded. Thanks in advance for any help.

//Get a CURL.
CURL *mCURL;
mCURL = curl_easy_init();

//Setup CURL to upload the torrent.
struct curl_httppost *post=NULL;
struct curl_httppost *last=NULL;
char *filename="filename.torrent";
curl_formadd(&post, &last, CURLFORM_COPYNAME, "upload_file",
CURLFORM_COPYCONTENTS, filename, CURLFORM_END);
curl_easy_setopt(mCURL, CURLOPT_POSTFIELDS, post);
curl_easy_setopt(mCURL, CURLOPT_POST, 1);
curl_easy_setopt(mCURL, CURLOPT_URL, "http://localhost/index.php");
                
//Post away
curl_easy_perform(mCURL);
Received on 2007-06-30