Save file or image programmatically. First get file from directory or URL. Then save the image and assign it to the field you wish.
Source code viewer
$image_url = 'http://example.com/image.png'; $node = node_load(1); // Edit the array directly. $node->field_image[LANGUAGE_NONE][0] = $file; node_save($node); // OR use entity metadata wrapper. $wrapper = entity_metadata_wrapper('node', $node); $wrapper->save();Programming Language: PHP