Attaching image files to nodes programmatically in Drupal 7

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

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

8条回答
  •  醉梦人生
    2020-12-07 14:29

    Here's one extra bit that tripped me up for a while: this will attach the image to the node, and if you're adding the image then you're okay. However, if you're updating an image, and you care about displaying it on a page, then one extra step is needed before calling node_save():

    image_path_flush($node->field_image['und'][0]['uri']);
    

    This will regenerate all of that image's styles.

提交回复
热议问题