Програмно добавить картинку к ноде Drupal6

  1. $user_uid = 1;
  2. $fid = 1 // для работы данного примеру нужен fid изображения
  3. $query =db_query("SELECT * FROM `files` WHERE fid = '$fid'");
  4. // Необходим путь к файлу картинки
  5. while($row = db_fetch_array($query)){
  6.  
  7. $filepath = $row['filepath'];
  8. $field = field_file_save_file($filepath, array(), file_directory_path());
  9. $file_obj = (object) $field;
  10. file_set_status($file_obj, 1);
  11. }
  12.  
  13. $node = new stdClass();
  14. $node->type = 'page';
  15. $node->title = 'title';
  16. $node->field_garbage_img[0]['fid'] = $file_obj->fid;
  17. $node->language = 'ru';
  18. $node->uid = $user_uid;
  19. $node->status = 1;
  20. $node->promote = 0;
  21. node_save($node);
Russian
Категория: 
The code has been tested and works
Мультитег: 

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Target Image