Hi,
I'm trying to save the path of an image, but after node_save($node); the dump inside my newly created node, is giving me only an empty $node->field_image_cache[0] object. The other values are saved. I don't know, which reference I should define. Thats my current status:
$node = new StdClass();
$node->uid = 4;
$node->type = 'product';
$node->status = 1;
$node->title = 'test';
$node->body = 'body';
$node->field_notice[0]['value'] = 'Testtext';
$node->field_image_cache[0]['filepath'] = 'sites/default/files/woman.png'; // is not saving
$node->field_image_cache[0]['value'] = 'sites/default/files/woman.png'; // is not saving
//save the node
node_save($node);
Hope somebody can help me. Best regards from Germany!
Comments
Comment #1
nevets commentedYour file needs to be first saved to the files table and the new fid used when saving the node.
Comment #2
jepster_Thanks for your reply. The example path with
$node->field_image_cache[0]['filepath'] = 'sites/default/files/woman.png';
is based on a file which is already uploaded and for which a fid is already created in the database. So how I can save my node with imagecache data?
Comment #3
nevets commentedNot sure of your goal, you save images with nodes, not image cache data. When you save a file/image with a node you save the fid.
Comment #4
jepster_When I save an image to the files-table, so how I can associate it with a specific node? I cannot find anything about that with googleing about drupal's node api.
Comment #5
nevets commentedIf you use drupal_write_record() to save the file, the data will have fid filled in on return which you can use with the file/image field when saving the node. Something like
Comment #6
jepster_After having a FID I still cannot save the image as a image cache content type. A simple image, without a image cache preset is working not, as well.
Here I'm:
Image cache array
Array for simple image data field
I'm saving with
Hope anybody can help me.
Comment #7
geraldito commentedThe only way I could make get it work was using Form API and a custom CCK field as described here: http://thedrupalblog.com/upload-image-using-forms-api-and-attach-it-imag...
Comment #8
ram4nd commentedI had the same problem, I wrote a little snippet with a solution that I used.
Save image programmatically in Drupal 7
Comment #9
fizk commentedPlease reopen if this is still an issue with ImageCache 6.x-2.0-rc1.