Created
March 5, 2014 07:05
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?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