我试图以编程方式创建节点。使用带有youtube扩展名的媒体模块,我想使用YouTube数据填充字段。从我至今读,它会是这个样子:Drupal 7 - 以编程方式创建节点,添加嵌入到字段的youtube
<?php
// $value in this case is the youtube ID.
$file = new stdClass();
$file->uid = 1;
$file->filename = $value;
$file->uri = 'youtube://v/' . $value;
$file->filemime = 'video/youtube';
$file->type = 'video';
$file->status = 1;
$youtube = file_save($file);
node->field_youtube[$node->language]['0']['fid'] = (array) $youtube->fid;
?>
我通过看在bartik主题$内容变量中的信息了解到这一点。但是,这会导致“错误的文件扩展名”错误。我也尝试将整个网址放在$ file-> uri中,并使用file_get_mimetype,然后它不会抛出错误,但视频也不起作用。有谁知道如何做到这一点?