Skip to content

Commit

Permalink
Facilitating downloads for message media
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyharris committed Jun 13, 2013
1 parent 038265a commit 4604632
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 6 deletions.
19 changes: 19 additions & 0 deletions download.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* Facilitates downloading a file
*/

if (!array_key_exists('file', $_GET) || !array_key_exists('filename', $_GET)) {
header('Location: '.$_SERVER['HTTP_REFERER']);
exit;
}

$file = urldecode($_GET['file']);
$filename = $_GET['filename'];
$headers = get_headers($file, 1);
$mimetype = $headers['Content-Type'];

header("Content-type: $mimetype");
header("Content-disposition: attachment; filename=\"$filename\"");

readfile($file);
11 changes: 5 additions & 6 deletions single-message.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
<div class="message-download">
<h3>Download</h3>
<?php
$downloader = $theme->info('base_url').'/download.php?';
if (!empty($meta['video_url'])) {
$icon = $theme->Html->image('video.png', array(
'alt' => 'Video',
'parent' => true
));
echo $theme->Html->tag('a', $icon, array(
'href' => $meta['video_url'],
'title' => 'Download Video',
'target' => '_blank'
'href' => $downloader.'file='.urlencode($meta['video_url']).'&filename='.urlencode(get_the_title()),
'title' => 'Download Video'
));
}
if (!empty($meta['audio_url'])) {
Expand All @@ -56,9 +56,8 @@
'parent' => true
));
echo $theme->Html->tag('a', $icon, array(
'href' => $meta['audio_url'],
'title' => 'Download Audio',
'target' => '_blank'
'href' => $downloader.'file='.urlencode($meta['audio_url']).'&filename='.urlencode(get_the_title()),
'title' => 'Download Audio'
));
}
?>
Expand Down

0 comments on commit 4604632

Please sign in to comment.