Does anyone have an example that can create everything that is need to make a new node work properly with imagefield when using Drupal 5?
This works with the Image Module but not imagefield.
global $user;
$node = new StdClass();
$node->type = 'image';
$node->uid = 20;
$node->status = 1;
$node->promote = 1;
$node->title = 'This is the title for the content';
$node->body = 'The body of the node';
$node->teaser = 'The teaser of the node';
$node->comment = 2;
$node->images = array();
$node->file = $node->images['_original'] = "files/images/temp/lastmail.jpg";
_image_build_derivatives($node, TRUE);
$node->new_file = TRUE;
node_save($node);
I attempted to make it the CCK way but no luck so far.
$node->field_img = array
(
0 => array
(
'fid' => "upload",
'title' => $file,
'alt' => $file,
'nid' => $node->nid,
'filename' => $file,
'filepath' => $dir.'/'.$file,
'filemime' => 'image/jpeg',
'filesize' => filesize($dir.'/'.$file),
)
);
Comments
Comment #1
uwe mindrup commentedI had the same problem and I did the "cck-way" in the following manner:
I put this code just before 'node_save($node)'.
Comment #2
quicksketchdrupal_execute is the usual way to insert data in a node form programmatically, unfortunately the file handling needs some additional help. See http://drupal.org/node/112802.
Comment #3
toxicdesign commented@Uwe Mindrup
I dont understand how you can do it that way when $node needs->to->be->an->abject? Not array?
I'm still stumped on this...I think I'm going to just insert the data with a db_query instead of fighting with this node_save vs imagefield battle.
Comment #4
jmlavarenne commentedBefore you save the node, you do this:
Comment #5
voipfc commentedIf you want to add more images to an existing node, how will you go about it?
Comment #6
jmlavarenne commentedYou could do node_load(), add the images as suggested, node_save().
Comment #7
Artem Beloglazov commentedtest variant: