Attaching image files to nodes programmatically in Drupal 7

前端 未结 8 1520
耶瑟儿~
耶瑟儿~ 2020-12-07 14:07

Is it possible to add an image to a node programmatically?

8条回答
  •  Happy的楠姐
    2020-12-07 14:24

    An easier way:

    $filename = 'image.txt';
    $image = file_get_contents('http://www.ibiblio.org/wm/paint/auth/gogh/gogh.white-house.jpg');
    $file = file_save_data($image, 'public://' . $filename, FILE_EXISTS_RENAME);
    $node->field_image = array(LANGUAGE_NONE => array('0' => (array)$file));
    

提交回复
热议问题