I'm working with Drupal 6开发者_开发百科 and the filefield module.
I created a simple form to upload an image to the server. I want to rename the file before it gets uploaded. I noticed that inside the field_file_save_upload
function, it is mentioned that implementing hook_file_insert
allows you to manipulate the file's properties. I'm not sure on how to implement this hook. Should I implement it in a new module or directly inside the field_file.inc file? Should it be named as field_file_insert
?
The documentation states the following:
/**
* 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)
To invoke a hook simply rename the 'hook_' to the name of your module like so
in your module somewhere:
function MYMODULENAME_file_insert(.....){
// Do things
}
Also just FYI: The hooks are provided so you don't have to modify core/contrib code to override/compliment existing functionality. It's not recommended to modify core/contrib files except for providing new generic functionality that your contributing back in the form of a patch :)
精彩评论