Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
I have a remote image URL address saved in $image_url variable and the following code to programmatically create a node:
$node = new stdClass();
$node->uid = '1';
$node->type = 'article';
node_object_prepare($node);
$node->title = $title;
$node->status = 1;
$node->promote = 0;
$node->sticky = 0;
$node->language = 'ru';
$node->body['und'][0]['value'] = $body;
$node->body['und'][0]['format'] = 'filtered_html';
node_save($node);
Calling filefield_sources_save_file($image_url)
in a custom module gives:
Warning: filesize(): stat failed for http://www.remotesite.com/images/2014/11/1414790760.jpg in filefield_sources_save_file() (line 451 of /home/mysite/public_html/sites/all/modules/filefield_sources/filefield_sources.module).
The specified file 1414790760.jpg could not be uploaded. Only files with the following extensions are allowed: jpg jpeg gif png txt doc xls pdf ppt pps odt ods odp.
Could you please help me to make changes into above peace of code to programmatically create a node with the image in the imagefield saved from a remote source.
Comments
Comment #1
yngens2 CreditAttribution: yngens2 commentedHad to take different path with file_save_data():
Let me know if there is nicer way of doing this with filefield_sources_save_file().