如何将许多现有文件与drupal文件夹相关联? [英] How can I associate many existing files with drupal filefield?

查看:62
本文介绍了如何将许多现有文件与drupal文件夹相关联?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从静态网站上存储了许多mp3文件,现在我们正在去drupal。我要为每个音频文件创建一个节点,但是我不想再次上传每个文件。我宁愿将文件复制到我想要的文件目录中,然后将节点与适当的文件相关联。

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?

谢谢!

推荐答案

我不知道我要去提出一种不同的方法,或者如果我要用不同的单词告诉你原来的问题,但是当你想要节点是文件时,我宁愿从文件开始生成节点,而不是将现有的节点与现有文件。

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.

在通用术语中,我将以编程方式执行:对于导入目录中的每个现有文件,我将构建 $ node 对象,然后调用 node_save($ node)将其存储在Drupal中。

In generic terms I would do it programmatically: for each existing files in your import directory I would build the $node object and then invoke node_save($node) to store it in Drupal.

Of在构建 $ node 对象的过程中,您将需要调用用于管理文件的模块的API函数。这是我写的一个类似的任务的示例代码。在这种情况下,我将产品表附加到产品(带有其他字段的节点),所以...

Of course in building the $node object 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_sheet 是产品节点中产品表的CCK字段

  • product 是节点类型

  • $ sheet_file 是产品表文件的完整引用(path + filename) / li>
  • field_sheet was the CCK field for the product sheet in the product node
  • product was the node type
  • $sheet_file was the complete reference (path + filename) to the product sheet file.

所以例子:

// Load the CCK field
$field = content_fields('field_sheet', 'product');
// Load the appropriate validators
$validators = array_merge(filefield_widget_upload_validators($field));
// Where do we store the files?
$files_path = filefield_widget_file_path($field);
// Create the file object
$file = field_file_save_file($sheet_file, $validators, $files_path);
// Apply the file to the field, this sets the first file only, could be looped
// if there were more files
$node->field_scheda = array(0 => $file);
// The file has been copied in the appropriate directory, so it can be
// removed from the import directory
unlink($sheet_file);

BTW:如果您使用库读取MP3元数据,可以设置$ node-> title和其他属性在一个明智的方式。

BTW: if you use a library to read MP3 metadata, you could set $node->title and other attributes in a sensible way.

希望这有帮助!

这篇关于如何将许多现有文件与drupal文件夹相关联?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆