Hi,
I tried simply to set it by defining on custom node creation like this:

$node->filed_fieldname[0]['filepath'] = $variable_holding_an_image_path_value;

The result was strange... Devel shows that filed_fieldname was created and 0 array was created but the 0 array is empty... May be that is because I have not defined all filed data?
Any way some of them gives me some trouble:
1. File id (fid) is there some hook to get the last one?
2. Time-stamp... is it counting days form our era or something?
3. Status what does that one means?

I really would be happy to here how to do this properly...
Anyway thanks for your help in advance ;)

Comments

quicksketch’s picture

The the handbook on programmaticly saving FileField entries. The only property you need to set is the "fid" property. http://drupal.org/node/330421

quicksketch’s picture

Status: Active » Closed (duplicate)
POVYLAZZZ’s picture

Thanks a lot.

POVYLAZZZ’s picture

Status: Closed (duplicate) » Active

Hello again...
I have included a script to include the image. It all seamed fine then I tried to edit the field I noticed that the field is empty. What could be the matter?
Here is the code:

  if(!isset($node->field_cover[0]['fid'])){
  $mime = 'image/jpeg';
 
   $file_drupal_path =  'the_path';

  $file = new stdClass();
  $file->filename = basename($file_drupal_path);
  $file->filepath = $file_drupal_path;
  $file->filemime = $mime;
  $file->filesize = filesize(file_directory_path().'/'.$file_drupal_path);

  $file->uid = $uid;
  $file->status = FILE_STATUS_PERMANENT;
  $file->timestamp = time();
  drupal_write_record('files', $file);
  $file->fid = db_result(db_query("SELECT fid FROM {files} WHERE filepath = '%s'", $file->filepath));
  
$node->field_cover = array(
    array(
'fid' => $file->fid,
'title' => basename($file->filename),
'filename' => $file->filename,
'filepath' => $file->filepath,
'filesize' => $file->filesize,
'mimetype' => $mime,
'description' => basename($file->filename),
'list' => 1,
'data'=>array('alt' => 'tekst',
'title' => 'title',
),
),
);
quicksketch’s picture

It doesn't look like you called node_save() after assembling the $node variable.

In any case, help with custom coding it outside the scope of help I provide in the issue queue.

POVYLAZZZ’s picture

Status: Active » Fixed

thanks node_save() fixed it ;) silly me :P

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.