function _attachment_links_download in Attachment Links 6
Download the given file over HTTP.
Parameters
$filepath The local path to the file.:
Return value
None if the call was successful. Returns a themed 404 error page if the file could not be found.
1 call to _attachment_links_download()
- attachment_links_retrieve in ./
attachment_links.module - Fetch the reqested file for the given node.
File
- ./
attachment_links.module, line 221 - The Attachment Links module provides permanent links to files attached to a node. A single, easy-to-remember URL can be used to retrieve the preferred (canonical) or newest version of a file regardless of how many versions of that file have been…
Code
function _attachment_links_download($filepath) {
// -- Copied from file_download().
if (file_exists(file_create_path($filepath))) {
$headers = module_invoke_all('file_download', $filepath);
if (in_array(-1, $headers)) {
return drupal_access_denied();
}
if (count($headers)) {
// -- PHP's basepath function screws up filenames with a space in them.
$parts = explode(DIRECTORY_SEPARATOR, $filepath);
$name = array_pop($parts);
// -- Backslashed escaped characters inside the filename value seem to
// -- confuse browsers, so double quotes are converted to single quotes.
// -- The browser will then adjust the filename to match the host OS'
// -- filename restrictions.
$name = str_replace('"', "'", $name);
$headers[] = 'Expires: 0';
$headers[] = 'Cache-Control: private';
$headers[] = 'Pragma: cache';
$headers[] = 'Content-Type: application/force-download';
$headers[] = 'Content-Disposition: attachment; filename="' . $name . '"';
file_transfer($filepath, $headers);
}
}
return drupal_not_found();
}