programmatically save image to node with link in custom module Im quite new to drupal 7. But my approach is learning by doing. This have worked fine until now....

My problem is, that I in a custom module, with a form submit, save a node with all the filled fields, including images. (Code below)

My problem is that i want to add a, a href to the images i save, so when opening the node the images will link to the link i have saved.

Is this even possible?

My node_save with pictures is like this:

$who = $user-&gt;uid;
$test = 'term_id' . $who;
$test1 = 'sales_id' . $who;
variable_set($test, $base_url . '/Sales/' . $form_state['values']['sales_id_terms']);
variable_set($test1, $base_url . '/Sales/' . $form_state['values']['sales_id_comp']);

$term_id = $form_state['values']['sales_id_terms'];
$file_temp_top = file_load($user-&gt;top_banner);
$file_temp_bund = file_load($user-&gt;bund_banner);
$file_temp_power = file_load(110);

//$file_temp_top = file_save_data($file_temp_top, 'public://firm_images/', FILE_EXISTS_REPLACE);

$node1 = new stdClass();  // Create a new node object
$node1-&gt;type = 'product_link';  // Content type
$node1-&gt;language = LANGUAGE_NONE;  // Or e.g. 'en' if locale is enabled
$node1 = node_submit($node1);
node_object_prepare($node1);  //Set some default values
$node1-&gt;status = 1;   // (1 or 0): published or unpublished
$node1-&gt;promote = 0;  // (1 or 0): promoted to front page or not
$node1-&gt;sticky = 0;  // (1 or 0): sticky at top of lists or not
$node1-&gt;comment = 1;  // 2 = comments open, 1 = comments closed, 0 = comments hidden


$node1-&gt;title = $form_state['values']['sales_name'] . '_1';
$node1-&gt;field_betingelser['und'][0]['value'] = $terms;
$node1-&gt;field_top_banner['und'][0] = array(
                'fid' =&gt; $file_temp_top-&gt;fid,
                'filename' =&gt; $file_temp_top-&gt;filename,
                'filemime' =&gt; $file_temp_top-&gt;filemime,
                'uri' =&gt; $file_temp_top-&gt;uri,
                'status' =&gt; 1,
                'display' =&gt; 1,
);
$node1-&gt;field_bund_banner['und'][0] = array(
                'fid' =&gt; $file_temp_bund-&gt;fid,
                'filename' =&gt; $file_temp_bund-&gt;filename,
                'filemime' =&gt; $file_temp_bund-&gt;filemime,
                'uid' =&gt; 1,
                'uri' =&gt; $file_temp_bund-&gt;uri,
                'status' =&gt; 1,
                'display' =&gt; 1,
);
$node1-&gt;field_powerd_by['und'][0] = array(
                'fid' =&gt; $file_temp_power-&gt;fid,
                'filename' =&gt; $file_temp_power-&gt;filename,
                'filemime' =&gt; $file_temp_power-&gt;filemime,
                'uid' =&gt; 1,
                'uri' =&gt; $file_temp_power-&gt;uri,
                'status' =&gt; 1,
                'display' =&gt; 1,
                'href' =&gt; $GLOBALS['root_url'] . '/new-products/',
);
$node1-&gt;field_terms_id['und'][0]['value'] = $form_state['values']['kon_id_terms'];

// Add author of the node
$node1-&gt;uid = $user-&gt;uid;

// Set created date
$node1-&gt;date = 'complaint_post_date';
$node1-&gt;created = strtotime('complaint_post_date');

$new_path = 'sales/' . $node1-&gt;field_terms_id['und'][0]['value'];
$node1-&gt;path = array('alias' =&gt; $new_path);

// Save the node
node_save($node1);
The file field will handle the display of the file regarding to its settings in the FieldUI.

So referencing the fid is sufficient:

$node1-&gt;field_top_banner['und'][0]['fid'] = $file_temp_top-&gt;fid;