Hi, sorry for my bad english.

I have a vocabulary with a file field and I would add some term for this vocabulary in batch mode.

how I could simulate upload button and "fake" managed_field?

My intent is to proceed in this "hackish" #1027068: Taxonomy CSV: Fields Support

Comments

robertom’s picture

I've solved.

Conceptually I've:

used file_unmanaged_copy() for copy file to the destination

created manually a file object for new file

and after used file_save()

$filepath = file_unmanaged_copy($source, $destination, FILE_EXISTS_RENAME);
if ($filepath !== FALSE) {
  $file = new stdClass();
  $file->uid = 1;
  $file->filename = basename($filepath);
  $file->uri = $filepath;
  $file->filemime = file_get_mimetype($filepath);
  $file->filesize = filesize($filepath);
  $file->status = 1;
  $file->timestamp = time();

  $file = file_save($file);
...
...

to see the context of this snippet see comment #9 at the #1027068: Taxonomy CSV: Fields Support