function privatemsg_attachments_file_download in Privatemsg 6.2
Implements hook_file_download().
File
- privatemsg_attachments/
privatemsg_attachments.module, line 417 - Allows users to add attachments to messages
Code
function privatemsg_attachments_file_download($filepath) {
global $user;
$filepath = file_create_path($filepath);
$result = db_query("SELECT f.*, pma.mid FROM {files} f INNER JOIN {pm_attachments} pma ON f.fid = pma.fid WHERE filepath = '%s'", $filepath);
if ($file = db_fetch_object($result)) {
// Try to load the message, pass user object to check recipient status.
if (user_access('view private message attachments') && privatemsg_message_load($file->mid, $user)) {
return array(
'Content-Type: ' . $file->filemime,
'Content-Length: ' . $file->filesize,
);
}
else {
return -1;
}
}
}