Software engineer, data guy, Open Source enthusiast, New Hampshire resident, husband, father. Fan of guitars, hiking, photography, homebrewing, sarcasm.
Drupal 6: Upload an image using the Forms API and attach it to a image/file field in a CCK node
In this tutorial I’ll show you how to upload an image using the Forms API, create a new node, and attach the image to the CCK (filefield/imagefield) field. I wrote this code to work with the modules I primarily use for image processing: cck, filefield, imageapi, imagecache, imagefield, mimedetect, and transliteration.
After I installed those modules I created a new node type (admin/content/types/add) called “Image” and added a single imagefield field.
Next I created a custom module with a hook_menu() implementation:
I defined the form function page callback:
This page callback function results in the following form:
Then I added the form validation and submit handler functions:
After using the form to upload an image, the following node was created: