幾周前我不得不做類似的事情,最後調整了Remote File module的一些功能,特別是remote_file_cck_attach_file()
功能。它使用filefield模塊中的field_file_save_file()
函數,這可能是您正在查找的函數。
就我而言,這些文件是從幾個遠程位置獲取的,並使用file_save_data()
臨時存儲。它們連接到一個CCK的FileField上hook_nodeapi()
presave問題,請使用下列內容:
public static function attachAsCCKField(&$node, $filepath, $fieldname, $index=0) {
// Grab the filefield definition
$field = content_fields($fieldname, $node->type);
$validators = array_merge(filefield_widget_upload_validators($field), imagefield_widget_upload_validators($field));
$fieldFileDirectory = filefield_widget_file_path($field);
// This path does not necessarily exist already, so make sure it is available
self::verifyPath($fieldFileDirectory);
$file = field_file_save_file($filepath, $validators, $fieldFileDirectory);
// Is the CCK field array already available in the node object?
if (!is_array($node->$fieldname)) {
// No, add a stub
$node->$fieldname=array();
}
$node->{$fieldname}[$index] = $file;
}
$filepath
是路徑,應附文件,$fieldname
是的FileField實例到節點和$index
中使用的內部名稱在多個字段條目的情況下將是附加文件的基於0的索引。
該函數在實用程序類中結束,因此爲verifyPath()調用的類語法。通話只是確保目標目錄可用:
public static function verifyPath($path) {
if (!file_check_directory($path, FILE_CREATE_DIRECTORY)) {
throw new RuntimeException('The path "' . $path . '" is not valid (not creatable, not writeable?).');
}
}
這對我來說 - 所有其他事情發生在節點自動保存。
我還沒有使用getid3模塊,所以我不知道它是否會與這種方式一起玩。另外,我不需要在文件字段中添加額外的信息/屬性,所以也許你不得不把更多的信息放到字段數組中,而不僅僅是field_file_save_file()
返回的文件。無論如何,希望這會有所幫助,祝你好運。
爲field_file_save_file()+1,這將節省我一些時間。 – 2009-10-30 06:22:13
看起來非常有希望,如果我沒有截止日期,我會深入挖掘並立即嘗試。 – googletorp 2009-10-30 14:56:34