Add image node with PHP Curl?
I have read a lot about about the topic. But I'm still a newbie and I'm having serious trouble. After using PHP/Curl to login, I move to the node/add/image page and get the token no problem. But I'm having trouble posting a new image node. I can get everything working when posting a new page node with Curl. It's just posting a new image node that's giving me trouble. Here is the code that should add the new image node. Curl fills out most of the image form fields such as title, body etc. All fields are populated by Curl *EXCEPT* the image file upload. And this seems to be what's stopping curl from creating the new image node. What am I doing wrong? How can I get Curl to fill in the file upload field? Any suggestions much appreciated! $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); I have reviewed the tutorials and snippets on the Drupal site (http://drupal.org/node/87711) and on other sites (http://www.voidberg.org/blog/using_php_and_curl_to_automate_drupal_tasks_suc...)
This seems like a lot of work. If you are trying to post an image remotely, any reason to not use XML-RPC? On 7/17/07, James Tunick <jt722@nyu.edu> wrote:
I have read a lot about about the topic. But I'm still a newbie and I'm having serious trouble.
After using PHP/Curl to login, I move to the node/add/image page and get the token no problem. But I'm having trouble posting a new image node. I can get everything working when posting a new page node with Curl. It's just posting a new image node that's giving me trouble.
-- Boris Mann Office 604-682-2889 Skype borismann http://www.bryght.com
On 7/17/07, James Tunick <jt722@nyu.edu> 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_h... Good luck, andrew
participants (3)
-
andrew morton -
Boris Mann -
James Tunick