how do I programmatically save nodes with multiple photo uploads? I have a very straight forward content type created in Drupal - Title, Body, Taxonomy term (drop down select, 1 value only), and Photos (multiple permitted, up to 8, alt and title tags are enabled).  I also have the meta

I have a set of CSV files with data for those fields with corresponding photos. I need to iterate over these programatically and use node_save() to get these in the database as well as upload the related photos.

I followed the direction here, and while it was a good start, I am still confused as to how to handle multiple uploads.

Bulk saving nodes with a file field

Can any suggest a tutorial or provide some sample code that can better illustrate how to do this?

EDIT:
Based on the direction below, this is the code I have come up with

$images = array();
foreach ($file_data_array as $csv_data) {
    foreach($image_array as $file_data) {
  $file = new stdClass();
  $file-&gt;filename = basename($file_data['filepath']);
  $file-&gt;filepath = $file_data['filepath'];
  $file-&gt;filemime = $file_data['mime'];
  $file-&gt;filesize = filesize($file_data['filepath']);
  $file-&gt;uid = $uid;
  $file-&gt;status = FILE_STATUS_PERMANENT;
  file_save($file);
  $images[] = array(
    'fid' =&gt; $file-&gt;fid,
    'alt' =&gt; $file_data['alt'],
    'title' =&gt; $file_data['title']
  );
}
$node = new stdClass;
$node-&gt;type = 'baby_clothes';
$node-&gt;body = 'body';
$node-&gt;title = 'title';
$node-&gt;uid = 1;
$node-&gt;status = 1;
$node-&gt;active = 1;

//the name of my actual field is 'product images'
$node-&gt;field_product_images[LANGUAGE_NONE] = $images;

//this is my actual taxonomy field
$node-&gt;field_baby_clothes_category[LANGUAGE_NONE][0]['tid'] = 2; //actual ID of the taxonomy for this node

node_save($node);
}


Thoughts?
You would normally just build up the files in a loop like so:

$images = array();

foreach ($file_data_array as $file_data) {
  $file = new stdClass();
  $file-&gt;filename = basename($file_data['filepath']);
  $file-&gt;filepath = $file_data['filepath'];
  $file-&gt;filemime = $file_data['mime'];
  $file-&gt;filesize = filesize($file_data['filepath']);

  $file-&gt;uid = $uid;
  $file-&gt;status = FILE_STATUS_PERMANENT;
  file_save($file);

  $images[] = array(
    'fid' =&gt; $file-&gt;fid,
    'alt' =&gt; $file_data['alt'],
    'title' =&gt; $file_data['title']
  );
}

$node = new stdClass;
// Build up the rest of the node as normal

$node-&gt;field_images[LANGUAGE_NONE] = $images;

node_save($node);


This assumes you have your CSV data loaded into an array called $file_data_array. 

fid, alt, title, height and width are the only columns available to an image field type so there's no need to build up an array for each field entry containing all the file details (you can ignore that bit in the other answer you linked to as it's unnecessary).

Also note the use of file_save() instead of drupal_write_record() to commit the file to the database...it's much better to use file_save() as it fires the necessary system hooks to let other modules react to your files being added.

Hope that helps