Pages

Tuesday, June 28, 2011

Drupal | programmatically create node with file field

$node = new StdClass();
        $node->type = 'bzl_img';
        $node->uid = $_GET['user_id'];
        $node->field_bzl_img_ref[0]['nid']=$_GET['bz_id'];
        $node->status = 0;
        $node->field_bzl_img_main[0]['value']=0;

        $node->field_bzl_user_img = array(
          array(
            'fid' => $fid,
            'title' => $FinalFilename,
            'filename' => $FinalFilename,
            'filepath' => $target,
            'filesize' => filesize($target),
            'mimetype' => $filemime,
            'data' => array(
              'description' => $FinalFilename,
            ),
            'list' => 1,
          ),
        );

        node_save($node);