_private_upload_create_url

Versions
6
_private_upload_create_url($file)

Create a URL for the file that changes if the file is public or private. TODO - Push to get a file_create_url hook into Drupal7.

Parameters

file object $file

Return value

str: the correct URL

▾ 3 functions call _private_upload_create_url()

private_upload_form_alter in contributions/private_upload/private_upload.module
hook_form_alter().
private_upload_views_handler_all_files in contributions/private_upload/private_upload.module
Display all files attached to a given node.
theme_private_upload_attachments in contributions/private_upload/private_upload.module
Displays file attachments in table. Taken from theme_upload_attachments.

Code

contributions/private_upload/private_upload.module, line 728

<?php
function _private_upload_create_url($file) {
  if (_private_upload_is_file_private($file->filepath)) {
    $download_method = variable_get('file_downloads', FILE_DOWNLOADS_PUBLIC); // this should be PUBLIC, but don't break misconfigured systems
    variable_set('file_downloads', FILE_DOWNLOADS_PRIVATE);
  }
  // Generate valid URL for both existing attachments and preview of new attachments (these have 'upload' in fid)     
  $href = file_create_url((strpos($file->fid, 'upload') === FALSE ? $file->filepath : file_create_filename($file->filename, file_create_path())));
  if (_private_upload_is_file_private($file->filepath)) {
    variable_set('file_downloads', $download_method);
  }
  return $href;
}
?>

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Web page addresses and e-mail addresses turn into links automatically.

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.