Fetch images across the internet with File API How can I use the FileAPI to fetch an image from another website via URL, and bring it into Drupal? Here is what I tried:

foreach ($data['photos'] as $item) {
            $photo = file_get_contents($item['url']);

            $filename = $entity-&gt;field_id['und'][0]['value'] . '-' . $x . '.jpg';

            $file = file_save_data($photo, 'public://' . $filename, FILE_EXISTS_REPLACE);

            if (is_object($file) &amp;&amp; file_exists($file-&gt;uri)) {
                $file-&gt;status = 1;
                $file = file_save($file);
                drupal_write_record('file_usage', $file);
                $entity-&gt;field_entity_image['und'][] = (array) $file;
                $x++;
            } else {
                // error
            }
        }


It doesn't quite work. The first time around it grabs some of the photos, then the second time around, it should remove any photos in the system and resave them (even if none changed), I have no way to tell if the remote file is new or not.
You might want to try just leaving the remote files as remote and have something like http://drupal.org/project/remote_stream_wrapper? There's an open issue in the module to add a field widget for image and file fields to support just a simple URL entry for a file.