Im新的drupal,现在我需要以编程方式创建节点。无法添加图像字段在Drupal 7
我可以创建一个简单的节点。但是如果我将它与图像领域结合,它总是失败。
$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.
检查您的图像文件夹的权限应该有'644'&还请检查您的系统日志错误提示.. – Rikesh 2012-01-30 05:37:55
你好,我也曾尝试过。我甚至将网站文件夹设置为777.我检查了日志,这里是我得到的。 “无法复制图像,因为目标目录public://配置不正确。” – claire 2012-01-30 07:39:46
'public' schema的默认路径是'/ sites/default/files',所以如果你想保存某些东西,例如'/ sites/default/files/my-images/image1.jpg',那么URI会是'public:// my-images/image1.jpg'。如果你保存这个节点作为表单提交的结果,我强烈建议查看['managed file' type](http://api.drupal.org/api/drupal/developer-- topic- forms_api_reference.html/7#managed_file)它将处理所有的文件保存为你 – Clive 2012-01-30 10:30:26