hook_file_transfer_alter

Function hook_file_transfer_alter() in uc_file.module:

<?php
  hook_file_transfer_alter
($file_user, $ip, $fid, $file)
?>


Description:

Stores, either for customization, copy protection or other reasons, might want to send customized downloads to customers. This hook will allow this to happen. Before a file is opened to be transfered to a customer, this hook will be called to make any altercations to the file that will be used to transfer the download to the customer. This, in effect, will allow a developer to create a new, personalized, file that will get transfered to a customer.

Parameters:
  • $file_user - the file_user object (i.e. an object containing a row from the uc_file_users table) that corresponds with the user download being accessed.
  • $ip - the IP address from which the customer is downloading the file
  • $fid - the file id of the file being transfered
  • $file - the file path of the file to be transfered
Return value:

The path of the new file to transfer to customer.


Example:

<?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;
}
?>