You are here

function hook_uc_file_transfer_alter in Ubercart 8.4

Same name and namespace in other branches
  1. 7.3 uc_file/uc_file.api.php \hook_uc_file_transfer_alter()

Makes changes to a file before it is downloaded by the customer.

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 transferred 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 transferred 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 transferred.

string $file: The file path of the file to be transferred.

Return value

string The path of the new file to transfer to customer.

1 invocation of hook_uc_file_transfer_alter()
DownloadController::transferDownload in uc_file/src/Controller/DownloadController.php
Sends the file's binary data to a user via HTTP and updates the database.

File

uc_file/uc_file.api.php, line 204
Hooks provided by the File Downloads module.

Code

function hook_uc_file_transfer_alter($file_user, $ip, $fid, $file) {

  // For large files this might be too memory intensive.
  $file_data = file_get_contents($file) . " [insert personalized data]";
  $new_file = tempnam(file_directory_temp(), 'tmp');
  file_put_contents($new_file, $file_data);
  return $new_file;
}