Browse Source

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.
pull/446/head
Adam Vessey 11 years ago
parent
commit
d35c482612
  1. 12
      includes/datastream.inc

12
includes/datastream.inc

@ -53,8 +53,16 @@ function islandora_view_datastream(AbstractDatastream $datastream, $download = F
if ($download) { if ($download) {
// Browsers will not append all extensions. // Browsers will not append all extensions.
$mime_detect = new MimeDetect(); $mime_detect = new MimeDetect();
$extension = $mime_detect->getExtension($datastream->mimetype); $extension = '.' . $mime_detect->getExtension($datastream->mimetype);
$filename = $datastream->label . '.' . $extension;
// 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\""); header("Content-Disposition: attachment; filename=\"$filename\"");
} }

Loading…
Cancel
Save