Skip to content

Instantly share code, notes, and snippets.

@batandwa
Created March 5, 2014 07:05
Show Gist options
  • Select an option

  • Save batandwa/9362513 to your computer and use it in GitHub Desktop.

Select an option

Save batandwa/9362513 to your computer and use it in GitHub Desktop.
Drupal 7 - Update a file or any other field on a taxonomy term
<?php
dsm(taxonomy_term_load(1060));
dsm(taxonomy_term_load(1064));
$term = taxonomy_term_load(1311);
$filepath = drupal_realpath('sites/powertech_crabtree/files/images/footer_logo_aberdare.png');
// Create managed File object and associate with Image field.
$file = (object) array(
'uid' => 1,
'uri' => $filepath,
'filemime' => file_get_mimetype($filepath),
'status' => 1,
);
// We save the file to the root of the files directory.
$file = file_copy($file, 'public://');
$term->field_image[LANGUAGE_NONE][0] = (array)$file;
dsm($term);
dsm(taxonomy_term_save($term));
(taxonomy_select_nodes(array(1311, 1064)));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment