I'm trying to write PHP to insert lots of content into my website's drupal 6 database. The content type has got 3 custom fields:
field_theme_preview_demo_link - text field
field_theme_preview_content_styl - text selector
field_theme_preview_thumb - image field with an 'alt'
I just copied the images over to the correct directory manually.
I created the content type (and manually inserted some content to confirm it was all ok).
I then found some code sample for programatically inserting content...
Creating Drupal CCK content programatically/ via API
and http://drupal.org/node/458778#comment-1653696 (for this one I couldnt understand the mod that is suggested for D6).
I tried to modify it but couldnt get it to work - it does create the new content but the image field is blank. (To run this code I just paste into the 'Execute PHP Code' block.)
global $user;
$newnode = new stdClass();
$newnode->title = 'New node title';
$newnode->body = "the body";
$newnode->uid = $user->uid;
$newnode->type = 'theme_preview';
$newnode->status = 1;
$newnode->promote = 0;
$newnode->active = 1;
$newnode->field_theme_preview_demo_link[0]['value'] = 'the link';
$newnode->field_theme_preview_content_styl[0]['value'] = 'Books';
$newnode->field_theme_preview_thumb = array(
array(
'fid' => 'upload',
'alt' => 'the alt',
'filename' => 'sites/default/files/theme_preview_thumbs/41531.jpg',
'filepath' => 'sites/default/files/theme_preview_thumbs',
'filesize' => filesize('sites/default/files/theme_preview_thumbs/41531.jpg'),
),
);
node_save($newnode);