views:

32

answers:

1

I am trying to attach multiple pictures to the node programmatically in drupal 7 but have no idea how. i am not even sure its possible. Here is my code for attaching one picture to the node and it works. Please if someone can help me how to attach multiple pictures more than one to the image field

$node->field_image['und'][0]['fid'] = $get_fid->fid;

A: 

i got it...first you have to change the image field settings to upload between 1 to 10 or unlimited than its very easy

foreach($sav_fid as $sn_fid) {
  $node->field_image['und'][$cnt_dlt]['fid'] = $sn_fid;
  $cnt_dlt++;
}

this will do it where field_image is the core image field attached to the node api.

['und'] is just a code for language i guess means undefined.

[$cnt_dlt] is a counter variable which initialise 0 than increase by 1 and this part is delta(this number will increase attach the imagae).

[fid] is the field_image reference to the file in the managed_file table.

$sn_fid is the fid(file id) from the managed_file table.

in order to create and attaching picture to a node by using node_save($node); you have upload the file by using file_copy($files); and save the fid by creating an object and saving the result from it.

Zero Cool

related questions