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