0

我正在使用 Drupal 6 和filefield 模块

我创建了一个简单的表单来将图像上传到服务器。我想在文件上传之前重命名文件。我注意到在field_file_save_upload函数内部,提到实现hook_file_insert允许您操作文件的属性。我不确定如何实现这个钩子。我应该在新模块中还是直接在 field_file.inc 文件中实现它?应该命名为field_file_insert?

该文档指出以下内容:

/**
 * Save a file upload to a new location.
 * The source file is validated as a proper upload and handled as such. By
 * implementing hook_file($op = 'insert'), modules are able to act on the file
 * upload and to add their own properties to the file.
 ...
 */
 function field_file_save_upload($source, $validators = array(), $dest = FALSE) 
4

1 回答 1

2

要调用钩子,只需将“hook_”重命名为模块的名称,如下所示

在你的模块某处:

function MYMODULENAME_file_insert(.....){
  // Do things
}

仅供参考:提供了挂钩,因此您不必修改核心/贡献代码来覆盖/赞美现有功能。不建议修改 core/contrib 文件,除非您以补丁的形式提供新的通用功能:)

于 2011-02-14T15:39:56.913 回答