You are here

function fillpdf_save_to_file in FillPDF 7

Same name and namespace in other branches
  1. 7.2 fillpdf.module \fillpdf_save_to_file()

Saves a PDF to a file.

_to_file

Parameters

object $pdf_info:

string $pdf_data:

array $token_objects:

string $output_name:

bool $redirect:

string|null $destination_path_override:

Return value

bool|string|void Nothing (if redirected), the path to the file (if saving the file succeeded), or FALSE (if it didn't).

Throws

\Exception

Deprecated

in fillpdf:7.x-1.10 and is removed from all future branches. Use fillpdf_action_save_to_file().

See also

https://www.drupal.org/project/fillpdf/issues/2538428

2 calls to fillpdf_save_to_file()
fillpdf_merge_handle_pdf in ./fillpdf.deprecated.inc
Figure out what to do with the PDF and do it.
fillpdf_rules_action_save_to_file in ./fillpdf.rules.inc
Save the PDF to a file and return the file path.

File

./fillpdf.deprecated.inc, line 106
Deprecated functions.

Code

function fillpdf_save_to_file($pdf_info, $pdf_data, $token_objects, $output_name, $redirect = TRUE, $redirect_to_file = FALSE, $destination_path_override = NULL) {
  if ($pdf_info->scheme === 'private') {
    throw new Exception('fillpdf_save_to_file() does not work properly with
    private files. Please use fillpdf_action_save_to_file() instead.');
  }
  if (isset($destination_path_override) && empty($destination_path_override) !== FALSE) {
    $destination_path = $destination_path_override;
  }
  if (empty($pdf_info->destination_path) && empty($destination_path_override)) {

    // If this function is called and the PDF isn't set up with a destination
    // path, give it one.
    $destination_path = 'fillpdf';
  }
  else {
    $destination_path = $pdf_info->destination_path;
  }
  $destination_path = _fillpdf_process_destination_path($pdf_info->destination_path, $token_objects);
  $path_exists = file_prepare_directory($destination_path, FILE_CREATE_DIRECTORY | FILE_MODIFY_PERMISSIONS);
  if ($path_exists === FALSE) {
    watchdog('fillpdf', "The path %destination_path does not exist and could not be\n      automatically created. Therefore, the previous submission was not saved. If\n      the URL contained download=1, then the PDF was still sent to the user's browser.\n      If you were redirecting them to the PDF, they were sent to the homepage instead.\n      If the destination path looks wrong and you have used tokens, check that you have\n      used the correct token and that it is available to FillPDF at the time of PDF\n      generation.", array(
      '%destination_path' => $destination_path,
    ));
  }
  else {

    // Full steam ahead!
    $saved_file_path = file_unmanaged_save_data($pdf_data, $destination_path . "/{$output_name}", FILE_EXISTS_RENAME);
    if ($redirect === TRUE) {
      if (isset($_GET['destination']) === FALSE) {

        // Should we send the user directly to the saved PDF? If so, do that.
        if ($redirect_to_file) {
          drupal_goto(file_create_url($saved_file_path));
        }
      }
    }
  }
  if ($redirect === TRUE) {

    // Allow the "destination" query string parameter to be used
    // for example, fillpdf?nid=1&fid=1&destination=node/1
    // If no destination is provided, drupal_goto() will send the
    // user to the front page.
    drupal_goto();
  }
  return $saved_file_path;
}