drake900918 2012-12-04 13:59
浏览 56

如何使用REST服务器PHP CURL在drupal 7中创建带有映像的节点?

I am trying to create a node with image using drupal 7 REST server, I have configured REST server properly, I am able to create node with simple text as its body, I want to able to post image also i.e. I should be able to display image in newly created node or at least should be able to attach image to node body? so far I am doing it like this, how can I attach/display image in node's body? I am doing this via an external PHP script

 $node_data = array(
  'title' => "this is test node",
  'type' => 'blog',
  'body[und][0][value]' => 'this is test node description'
);

$node_data = http_build_query($node_data);
$cookie_session = $logged_user->session_name . '=' . $logged_user->sessid;

// cURL
$curl = curl_init($request_url);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Accept: application/json')); // Accept JSON response
curl_setopt($curl, CURLOPT_POST, 1); // Do a regular HTTP POST
curl_setopt($curl, CURLOPT_POSTFIELDS, $node_data); // Set POST data
curl_setopt($curl, CURLOPT_HEADER, FALSE);  // Ask to not return Header
curl_setopt($curl, CURLOPT_COOKIE, "$cookie_session"); // use the previously saved session
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_FAILONERROR, TRUE);

$response = curl_exec($curl);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
  • 写回答

1条回答 默认 最新

  • dtkjthe4025 2012-12-04 16:07
    关注

    OK I am able to post images to newly created drupal node. I managed to do it by specifying the node body as "full_html". added following parameter in node_data array

    'body[und][0][format]' =>'full_html'
    

    with this I can post content as html content, hence image can be embedded in it.

    BTW there are three options are available:

    filtered_html
    full_html
    plain_text
    
    评论

报告相同问题?

悬赏问题

  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据
  • ¥20 软件测试决策法疑问求解答
  • ¥15 win11 23H2删除推荐的项目,支持注册表等