Search code examples
phpimagedrupalfieldexecute

drupal_execute populating image field


How to populate image field value with drupal_execute.

for ex my content type (test) has two additional fields 1. photo (image filed), 2. phid (text field)

for phid $form_state['values']['field_phid'][0]['value'] ='14'; . how to populate photo which is image field type


Solution

  • i found the solution as below . i dont know pros and cons but it works fine for me.

    $image = "*******/test.jpg";
    $field = content_fields('field_img', 'img_test');
    $validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
    $files_path = filefield_widget_file_path($field);
    $form_state['values']['field_img'][]= field_file_save_file($image, $validators, $files_path, FILE_EXISTS_REPLACE);