Skip to content
This repository was archived by the owner on Sep 10, 2021. It is now read-only.

Commit c7ea6ed

Browse files
committed
BUG: refs #260. Fix item download functionality for single bitstream items
1 parent 5cd8ac9 commit c7ea6ed

File tree

1 file changed

+43
-42
lines changed

1 file changed

+43
-42
lines changed

core/views/download/onebitstream.phtml

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,23 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
1010
PURPOSE. See the above copyright notices for more information.
1111
=========================================================================*/
1212

13-
$chunkSize = 1*(1024*8);
13+
$chunkSize = 1024 * 8;
1414
$buffer = '';
15-
$fileSize = @filesize($this->path);
15+
$fileSize = filesize($this->path);
1616
$handle = fopen($this->path, 'rb');
1717

18-
$contenType=$this->mimetype;
18+
$contentType = $this->mimetype;
1919

20-
if ($handle === false)
20+
if($handle === false)
2121
{
2222
throw new Zend_Exception("Unable to open the file ");
2323
}
2424
$modified = gmdate('D, d M Y H:i:s').' GMT';
25-
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
26-
header("Last-Modified: $modified");
25+
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
26+
header('Last-Modified: '.$modified);
2727

2828
// if pdf set the content-type acordingly
29-
if(!isset($contentType)&&pathinfo($this->name, PATHINFO_EXTENSION) == "pdf")
29+
if(!isset($contentType) && pathinfo($this->name, PATHINFO_EXTENSION) == 'pdf')
3030
{
3131
$contentType = 'application/pdf';
3232
$enableContentDisposition = false;
@@ -38,74 +38,75 @@ if(!isset($contentType))
3838
}
3939

4040
// Hack for .vsp files (for OSA)
41-
if(!isset($contentType)&&strlen($this->name)>4 && substr($this->name,strlen($this->name)-4,4)==".vsp")
41+
if(!isset($contentType) && strlen($this->name) > 4 && substr($this->name,strlen($this->name) - 4, 4) == '.vsp')
4242
{
4343
$contentType = 'application/isp';
4444
}
45-
46-
4745

4846
$agent = env('HTTP_USER_AGENT');
49-
if (preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent))
47+
if(preg_match('%Opera(/| )([0-9].[0-9]{1,2})%', $agent) || preg_match('/MSIE ([0-9].[0-9]{1,2})/', $agent))
5048
{
5149
header('Content-Type: '.$contentType);
52-
header("Content-Disposition: attachment; filename=\"".$this->name."\";");
53-
header("Expires: 0");
50+
header('Content-Disposition: attachment; filename="'.$this->name.'";');
51+
header('Expires: 0');
5452
header('Accept-Ranges: bytes');
55-
header("Cache-Control: private", false);
56-
header("Pragma: private");
53+
header('Cache-Control: private', false);
54+
header('Pragma: private');
5755
$httpRange = env('HTTP_RANGE');
58-
if ( isset ($httpRange))
56+
if(isset($httpRange))
5957
{
6058
list ($toss, $range) = explode("=", $httpRange);
6159
str_replace($range, "-", $range);
62-
$size = $fileSize-1;
63-
$length = $fileSize-$range;
64-
header("HTTP/1.1 206 Partial Content");
65-
header("Content-Length: $length");
66-
header("Content-Range: bytes $range$size/$fileSize");
60+
$size = $fileSize - 1;
61+
$length = $fileSize - $range;
62+
header('HTTP/1.1 206 Partial Content');
63+
header('Content-Length: '.$length);
64+
header('Content-Range: bytes '.$range.$size.'/'.$fileSize);
6765
fseek($handle, $range);
6866
}
6967
else
7068
{
71-
header("Content-Length: ".$fileSize);
69+
header('Content-Length: '.$fileSize);
7270
}
7371
}
7472
else
7573
{
7674
header('Accept-Ranges: bytes');
77-
header("Expires: 0");
78-
header("Content-Type: ".$contentType);
79-
header("Content-Length: ".$fileSize);
80-
if(!isset($enableContentDisposition) || $enableContentDisposition==true)
75+
header('Expires: 0');
76+
header('Content-Type: '.$contentType);
77+
header('Content-Length: '.$fileSize);
78+
if(!isset($enableContentDisposition) || $enableContentDisposition == true)
8179
{
82-
header("Content-Disposition: attachment; filename=\"".$this->name."\";");
80+
header('Content-Disposition: attachment; filename="'.$this->name.'";');
8381
}
84-
if ( isset ($httpRange))
82+
if(isset($httpRange))
8583
{
86-
list ($toss, $range) = explode("=", $httpRange);
87-
str_replace($range, "-", $range);
88-
$size = $fileSize-1;
89-
$length = $fileSize-$range;
90-
header("HTTP/1.1 206 Partial Content");
91-
header("Content-Length: $length");
92-
header("Content-Range: bytes $range$size/$fileSize");
84+
list($toss, $range) = explode('=', $httpRange);
85+
str_replace($range, '-', $range);
86+
$size = $fileSize - 1;
87+
$length = $fileSize - $range;
88+
header('HTTP/1.1 206 Partial Content');
89+
header('Content-Length: '.$length);
90+
header('Content-Range: bytes '.$range.$size.'/'.$fileSize);
9391
fseek($handle, $range);
9492
}
9593
}
96-
@ob_end_clean();
97-
@ob_start();
9894

99-
while (!feof($handle) && connection_status() == 0)
95+
set_time_limit(0);
96+
97+
//kill the whole ob stack (Zend uses double nested output buffers)
98+
while(ob_get_level() > 0)
99+
{
100+
ob_end_clean();
101+
}
102+
103+
while(!feof($handle) && connection_status() == 0)
100104
{
101-
set_time_limit(0);
102105
$buffer = fread($handle, $chunkSize);
103106
echo $buffer;
104-
@flush();
105-
@ob_flush();
106107
}
107108
fclose($handle);
108-
exit ((connection_status() == 0) && !connection_aborted());
109+
exit(connection_status() == 0 && !connection_aborted());
109110

110111

111112

0 commit comments

Comments
 (0)