문제

I'm in the progress of creating a bulk upload function for a Drupal site. Using flash I'm able to upload the files to a specific url that should be able to handle the files.

What I want to do, is not just to upload the files, but create a node of a specific type with the file saved to a file-field that has been setup with CCK. Since these are audio files, it's important that file-field handles the files, so additional meta data can be provided with the getid3 module.

I've taken a look at the code/doc, but wasn't able on the first round to figure out how to handle this. Ideally, there is some function that I've missed, that can handle most of this for me.

If any one has experience with this I would apreciate some pointers on how to approach this matter.

도움이 되었습니까?

해결책

It's pretty straight forward, setup your content type with the required fields, then you want to use code similar to this:

$file = new stdClass();
$file->filename = basename($filepath);
$file->filepath = $filepath;
$file->filemime = $mime;
$file->filesize = filesize($filepath);

$file->uid = $uid;
$file->status = FILE_STATUS_PERMANENT;
$file->timestamp = time();
drupal_write_record('files', $file);


$node = new StdClass();
$node->type = 'type';
$node->body = 'body';
$node->title = 'title';
$node->field_file = array(
  array(
    'fid' => $file->fid,
    'title' => basename($file->filename),
    'filename' => $file->filename,
    'filepath' => $file->filepath,
    'filesize' => $file->filesize,
    'mimetype' => $mime,
    'data' => array(
      'description' => basename($file->filename),
    ),
    'list' => 1,
  ),
);
$node->uid = 1;
$node->status = 1;
$node->active = 1;
$node->promote = 1;
node_save($node);
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 drupal.stackexchange
scroll top