0

使用 print_r 我得到:

stdClass Object
(

 [field_car_image] => Array
    (
        [0] => Array
            (
                [filename] => HERMAN 096.jpg
                [filepath] => sites/default/files/HERMAN 096.jpg
                [filemime] => image/jpeg
                [filesize] => 933105
                [status] => 1
            )

    )
 ..... // the rest is also on here

它完美地保存了所有其他数据,而不是图像。后:

node_object_prepare($node); 
$node = node_submit($node);
node_save($node);

我在 $node 对象上做了一个 print_r,并且没有引用“field_car_image”。有人知道如何正确保存文件字段吗?

4

1 回答 1

2

您缺少 filefield 数组中表文件的 fid(文件 ID);要在 drupal 中正确上传文件,请务必使用 file_save_upload 函数http://api.drupal.org/api/function/file_save_upload/6

此代码向您展示如何将文件字段保存到节点中。

 $node->field_car_image = array(0=>array(
            'fid'=>$fid,//get this value from the file object returned by file_save_upload
            'uid'=>$uid,//user ID
            'filename'=>$filename,
            'filepath'=>$filepath,
            'filemime'=>$filemime,
            'filesize'=>$filesize,
            'status'=>$status,
            'timestamp'=>$timestamp,
        ),
    );
于 2010-10-14T08:20:34.080 回答