I have many mp3 files stored on my server already from a static website, and we’re now moving to drupal. I’m going to create a node for each audio file, but I don’t want to have to upload each file again. I’d rather copy the files into the drupal files directory where I want them, and then associate the nodes with the appropriate file.
Any ideas on how to accomplish that?
Thanks!
I am not sure if I am going to propose a different approach or if I am about to tell with different words what you already meant with your original question, but as you want the nodes to be the files, I would rather generate the nodes starting from the files, rather than associating existing nodes with existing files.
In generic terms I would do it programmatically: for each existing files in your import directory I would build the
$nodeobject and then invokenode_save($node)to store it in Drupal.Of course in building the
$nodeobject you will need to invoke the API function of the module you are using to manage the files. Here’s some sample code I wrote to do a similar task. In this scenario I was attaching a product sheet to a product (a node with additional fields), so…field_sheetwas the CCK field for the product sheet in the product nodeproductwas the node type$sheet_filewas the complete reference (path + filename) to the product sheet file.So the example:
BTW: if you use a library to read MP3 metadata, you could set $node->title and other attributes in a sensible way.
Hope this helps!