Programmatically insert an image with caption I'm trying to attach programmatically an Image with caption to my node.
I'm using image_field_caption module.

    $node = node_load($nid);

    $path = "images/gallery_articolo/".$value['foto'];
    $filetitle = $value['desc'];
    $filename = $value['foto'];

    $file_temp = file_get_contents($path);
    $file_temp = file_save_data($file_temp, 'public://' . $filename, FILE_EXISTS_RENAME);

    $node-&gt;field_steps['und'][($value['order'] - 1)] = array(
        'image_field_caption' =&gt; array( 'value' =&gt; $value['desc'], 'format' =&gt; 'full_html'),
        'fid' =&gt; $file_temp-&gt;fid,
        'filename' =&gt; $file_temp-&gt;filename,
        'filemime' =&gt; $file_temp-&gt;filemime,
        'uid' =&gt; 1,
        'uri' =&gt; $file_temp-&gt;uri,
        'status' =&gt; 1
    );

    node_save($node);


I followed the stucture seen in devel, but I have a lot of issues..

This is the recent log entry: 

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'caption' cannot be null: 
INSERT INTO {field_image_field_caption_revision} (field_name, entity_type, entity_id, revision_id, bundle, delta, language, caption, caption_format) 
VALUES (
:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8), (:db_insert_placeholder_9, :db_insert_placeholder_10, :db_insert_placeholder_11, :db_insert_placeholder_12, :db_insert_placeholder_13, :db_insert_placeholder_14, :db_insert_placeholder_15, :db_insert_placeholder_16, :db_insert_placeholder_17); 
Array ( [:db_insert_placeholder_0] =&gt; field_steps [:db_insert_placeholder_1] =&gt; node [:db_insert_placeholder_2] =&gt; 455 [:db_insert_placeholder_3] =&gt; 863 [:db_insert_placeholder_4] =&gt; article [:db_insert_placeholder_5] =&gt; 0 [:db_insert_placeholder_6] =&gt; und [:db_insert_placeholder_7] =&gt; [:db_insert_placeholder_8] =&gt; [:db_insert_placeholder_9] =&gt; field_steps [:db_insert_placeholder_10] =&gt; node [:db_insert_placeholder_11] =&gt; 455 [:db_insert_placeholder_12] =&gt; 863 [:db_insert_placeholder_13] =&gt; article [:db_insert_placeholder_14] =&gt; 2 [:db_insert_placeholder_15] =&gt; und 
[:db_insert_placeholder_16] =&gt; Wild Roses: fiori che sembrano appena sbocciati, che sottolineano ancora una volta la sua grande cifra stilistica, composizioni perfette per ogni dolce e speciale occasione. 
[:db_insert_placeholder_17] =&gt; full_html ) in image_field_caption_field_attach_update() (line 234 of /sites/all/modules/image_field_caption/image_field_caption.module).


But, as you can see, the :db_insert_placeholder_16 is valorized.
Can someone locate where the error is?
I can't find it..

Thank you ^^
in the log entry it shows that [:db_insert_placeholder_7] and [:db_insert_placeholder_8] elements of the Array were empty - that might be the reason why Insert statement failed for the caption field: 

Array 
( 
[:db_insert_placeholder_0] =&gt; field_steps 
[:db_insert_placeholder_1] =&gt; node 
[:db_insert_placeholder_2] =&gt; 455 
[:db_insert_placeholder_3] =&gt; 863 
[:db_insert_placeholder_4] =&gt; article 
[:db_insert_placeholder_5] =&gt; 0 
[:db_insert_placeholder_6] =&gt; und 
[:db_insert_placeholder_7] =&gt; 
[:db_insert_placeholder_8] =&gt; 
[:db_insert_placeholder_9] =&gt; field_steps 
[:db_insert_placeholder_10] =&gt; node 
[:db_insert_placeholder_11] =&gt; 455 
[:db_insert_placeholder_12] =&gt; 863 
[:db_insert_placeholder_13] =&gt; article 
[:db_insert_placeholder_14] =&gt; 2 
[:db_insert_placeholder_15] =&gt; und 
[:db_insert_placeholder_16] =&gt; Wild Roses: fiori che sembrano appena sbocciati, che sottolineano ancora una volta la sua grande cifra stilistica, composizioni perfette per ogni dolce e speciale occasione. 
[:db_insert_placeholder_17] =&gt; full_html 
) 
in image_field_caption_field_attach_update() (line 234 of /sites/all/modules/image_field_caption/image_field_caption.module).


also, [:db_insert_placeholder_16] - contains a string with 173 characters - is the caption field big enough?

hope this helps