[development] Add image node with PHP Curl?
James Tunick
jt722 at nyu.edu
Sat Jul 21 02:29:59 UTC 2007
That was it- it works now. I thought I had tried that, but I guess not. Thank you so much, Andrew!
For others, here is the code...
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL,"http://www.example.com/?q=node/add/image/");
curl_setopt($ch, CURLOPT_POST, 1);
$postarray = array(
'files[image]' =>"@$file",
'taxonomy[3]'=>'2',
'title' => $file,
'body' => 'xxxx',
'status' => '1',
'revision' => '1',
'comment' => '2',
'name' => 'mov',
'moderate' => '0',
'form_id' => 'image_node_form',
'form_token' => $token,
'op' => 'Submit'
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postarray);
$buf2 = curl_exec ($ch);
curl_close ($ch);
On 7/17/07, James Tunick wrote:
$postarray = array(
'files[image]' =>'@$file',
'taxonomy[3]'=>'2',
'title' => $file,
'body' => 'xxxx',
If this is the actual code you're using, I think the problem is that
you're not passing in the file name correctly. The single quotes wont
allow for the variable substitution needed to insert your filename.
I've got an old blog post with some sample code:
http://drewish.com/blogger/archives/2005/01/27/using_php_and_curl_to_do_an_html_file_post.html
Good luck,
andrew
More information about the development
mailing list