php – 无法在drupal 7中添加图像字段

我是drupal的新手,现在我需要以编程方式创建节点.

我能够创建一个简单的节点.但如果我将它与图像字段合并,它总是失败.

$file_path = drupal_realpath('tmp/test_image.jpg');
$file = (object) array(
    'uid' => 1,
    'uri' => $file_path,
    'filemime' => file_get_mimetype($file_path),
    'status' => 1,
);
$copy = file_copy($file, 'public://sites/default/files/field/image/testing/', FILE_EXISTS_RENAME);
$node->field_image[LANGUAGE_NONE][0] = (array) $copy;

它总是给我一个错误:(

The specified file could not be copied, because the destination directory is not properly configured. This may be caused by a problem with file or directory permissions. More information is available in the system log.

最佳答案 我有同样的问题.

在我的情况下,问题是媒体配置“公共文件系统路径”被设置为相对路径站点/默认/文件.之后我设置了从根开始的绝对路径

点赞