From d35c4826120752709b33f492f2e451bac0972c8b Mon Sep 17 00:00:00 2001 From: Adam Vessey Date: Thu, 16 Jan 2014 20:12:00 +0000 Subject: [PATCH] Avoid adding on duplicate extensions. As we often use filenames for datastream labels, and then use the labels to generate file names for download, we were ending up with file extensions being doubled up. --- includes/datastream.inc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/includes/datastream.inc b/includes/datastream.inc index 72a86c5f..26a7a8d5 100644 --- a/includes/datastream.inc +++ b/includes/datastream.inc @@ -53,8 +53,16 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F if ($download) { // Browsers will not append all extensions. $mime_detect = new MimeDetect(); - $extension = $mime_detect->getExtension($datastream->mimetype); - $filename = $datastream->label . '.' . $extension; + $extension = '.' . $mime_detect->getExtension($datastream->mimetype); + + // Prevent adding on a duplicate extension. + $extension_length = strlen($extension); + $duplicate_extension_position = strripos($datastream->label, $extension, -$extension_length); + $filename = $datastream->label; + if ($duplicate_extension_position === FALSE) { + $filename .= $extension; + } + header("Content-Disposition: attachment; filename=\"$filename\""); }