I would like to be able to import files with the node import. This can be achieved with the following code (I think):
$file = new stdClass();
$file->filename = basename($filename);
$file->filepath = $filename;
$file->filemime = $mime;
$file->filesize = filesize($filename);
$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));
Use case:
I have a directory of files for the letter "k" with about 400 files. Each file corresponds to a dictionary entry. I made a script to merge the results, and a line looks like this:
kátaloga;katalog;s.;0001;words/se/k/0001.mp3;words/nb/k/0013.mp3
Ideally the above code would enable a function for selecting the fifth field for creating the file and return the fid which is needed for inserting in the filefield cck. (At least the latest 5 version of Node Import only lets me give fid to the filefield, and not a filename). All derived filefield fields ask for the fid. So this would work with audio filefield and filefield image.
The same would probably apply for image and audio nodes as well.
For importing images I'm not sure if there needs to be a call for image cache, or if image cache automagically will notice the new images and resize when needed. The same for image.
I looked into the 6.x-1.x-dev files but couldn't immediately see where the field mappings are done.
Best regards,
Paul
Comments
Comment #1
pkej commentedI would prefer audio and image node support, so in effect this would need to create a node after creating the file, and then reference the node; so this functionality would also support node reference fields, and thus create more than one node per row of csv import.
It might also have to check if it can find the fid before inserting the file into the files table, to make sure that we don't duplicate the entries.
Comment #2
pkej commentedI've created a howto with working code for importing files from a local path to a node just created:
http://drupal.org/node/330421
Comment #3
dirkson commentedsubscribe
Comment #4
Robrecht Jacques commentedFiles can be imported in 6.x if you move the file to the right location prior to doing the import.