Module Development

Movie Project: Fetch and Attach an Image File for Drupal 7

This page is archived

We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.

Create an image file programmatically and attach a file to a node.

Goal

Attach a file to a programmatically-created node.

Prerequisites

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.

  1. Understand how to create files programmatically and attach them to nodes.
  2. Use PHP to validate and create sensible filenames.

Tasks

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.

Recap

  • 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

Additional resources

Creative Commons License

Drupal Training Resources by Damian Robinson are licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. Based on a work at http://www.damianrobinson.co.uk.

Hands-On Exercises: Movie Project