Jump to content

sending a POST (with a file) using curl


awi

Recommended Posts

Hi again, I posted a msg earlier regarding the same problem but this time I'm going to try CURL instead of fsockopen (giving up for now).

 

Ok, so I'm trying to POST some data including a file (as if you are sending a multi-part html form) using curl. Here is what I'm trying to run:

 

$fileToSend = join("", file($file)); // $file is name of file and it resides in same dir as this script
$postfields = array(
         'clip.category' => $someCatId,
         'clip.tags' => $someTag,
         'clip.title' => $title,
         'clip.description' => $desc,
         'clip.language' => 'en',
         'clip.file' => "@$fileToSend");

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $res);
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
//curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); 
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "$postfields");
// execute curl command
$result = curl_exec($ch);

print '<pre>';
print_r($result);
exit;

 

My $result is empty, I get a blank page.

 

1) Do you see anything wrong with my code?

2) I do not have access to the "receving" end of this. How ould you diagnose problems without that kind of access.

 

Thanks again for your help

CA

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.