函数hook_file_transfer_alter()位于uc_file.module模块中:
<?php
hook_file_transfer_alter($file_user, $ip, $fid, $file)
?>
描述:
对于drupal网店,无论是出于个性化的原因,还是出于版权保护的原因,或者其它原因,可能想要给客户发送定制化的下载文件。使用这个钩子就可以实现这一点。在将文件传递给客户以前,将会调用这个钩子,来对文件进行一些修改,从而实现文件对于客户而言的定制化。实际上,开发者利用这一点,就可以创建一个新的 ,个性化的文件,来传递给相应的客户。
参数:
· $file_user -正在下载文件的用户所对应的对象(比如,一个包含了一个uc_file_users表中一行记录的对象)。
· $ip - 客户下载文件所用的IP地址
· $fid - 正在传递的文件的文件id
· $file -正在传递的文件的路径
返回值:
要传递给客户的新文件的路径
例如:
<?php
/* Inside personal_text module - will place personalized text at the end of a file */
function personal_text_file_transfer_alter($file_user, $ip, $fid, $file) {
$file_data = file_get_contents($file)." [insert personalized data]"; //for large files this might be too memory intensive
$new_file = tempnam(file_directory_temp(),'tmp');
file_put_contents($new_file,$file_data);
return $new_file;
}
?>
相关链接: Think in Drupal