Attaching files to nodes programmatically in Drupal 7

$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));

Source from....

http://stackoverflow.com/questions/5129559/attaching-files-to-nodes-programmatically-in-drupal-7

Comments

Popular posts from this blog

How to Reset Root Password in Drupal 7 with phpMyAdmin

Drupal - Hiding field group and its Children