I am in middle of coding creating nodes programatically. Here i have one problem. I need to programmatically attach image to the content type from local system folder. I mean my image path example 'c://xxxxx/xxxx/images/img.jpg'.
Thanks in advance for your advice.
Hi i used this code and work fine in the localhost. But it's failed when i work on the server.
$filepath = drupal_realpath('misc/druplicon.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://'); $node->field_image[LANGUAGE_NONE] = (array)$file;
Reference link : attaching-files-to-nodes-programmatically-in-drupal-7
I didn't get the solution yet. Can any one have the experience?