Check your version
This tutorial covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.
Create an image file programmatically and attach a file to a node.
Attach a file to a programmatically-created node.
You will need the following knowledge and skills. If you need a review, check out the Additional resources section at the bottom of this page.
- Understand how to create files programmatically and attach them to nodes.
- Use PHP to validate and create sensible filenames.
Create a function to download a movie poster using The Movie DB API and save it as a file.
Attach the saved file to the node.
- Files are created as separate objects and associated with nodes.
- When integrating with other systems, we often have to sanitize content before using it.
Further your understanding
- Continue to the next lesson: Movie Project: Create Taxonomy Terms Programmatically.
- API Documentation: Drupal file functions (api.drupal.org)
- API Documentation: Node API Hooks (api.drupal.org)
- PHP Documentation: PHP string functions (php.net)