@@ -10,23 +10,23 @@ the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
10
10
PURPOSE. See the above copyright notices for more information.
11
11
=========================================================================*/
12
12
13
- $ chunkSize = 1 *( 1024 * 8 ) ;
13
+ $ chunkSize = 1024 * 8 ;
14
14
$ buffer = '' ;
15
- $ fileSize = @ filesize ($ this ->path );
15
+ $ fileSize = filesize ($ this ->path );
16
16
$ handle = fopen ($ this ->path , 'rb ' );
17
17
18
- $ contenType = $ this ->mimetype ;
18
+ $ contentType = $ this ->mimetype ;
19
19
20
- if ($ handle === false )
20
+ if ($ handle === false )
21
21
{
22
22
throw new Zend_Exception ("Unable to open the file " );
23
23
}
24
24
$ 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 );
27
27
28
28
// 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 ' )
30
30
{
31
31
$ contentType = 'application/pdf ' ;
32
32
$ enableContentDisposition = false ;
@@ -38,74 +38,75 @@ if(!isset($contentType))
38
38
}
39
39
40
40
// 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 ' )
42
42
{
43
43
$ contentType = 'application/isp ' ;
44
44
}
45
-
46
-
47
45
48
46
$ 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 ))
50
48
{
51
49
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 ' );
54
52
header ('Accept-Ranges: bytes ' );
55
- header (" Cache-Control: private " , false );
56
- header (" Pragma: private " );
53
+ header (' Cache-Control: private ' , false );
54
+ header (' Pragma: private ' );
57
55
$ httpRange = env ('HTTP_RANGE ' );
58
- if ( isset ($ httpRange ))
56
+ if ( isset ($ httpRange ))
59
57
{
60
58
list ($ toss , $ range ) = explode ("= " , $ httpRange );
61
59
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 );
67
65
fseek ($ handle , $ range );
68
66
}
69
67
else
70
68
{
71
- header (" Content-Length: " .$ fileSize );
69
+ header (' Content-Length: ' .$ fileSize );
72
70
}
73
71
}
74
72
else
75
73
{
76
74
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 )
81
79
{
82
- header (" Content-Disposition: attachment; filename= \"" .$ this ->name ."\" ; " );
80
+ header (' Content-Disposition: attachment; filename=" ' .$ this ->name .' "; ' );
83
81
}
84
- if ( isset ($ httpRange ))
82
+ if ( isset ($ httpRange ))
85
83
{
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 );
93
91
fseek ($ handle , $ range );
94
92
}
95
93
}
96
- @ob_end_clean ();
97
- @ob_start ();
98
94
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 )
100
104
{
101
- set_time_limit (0 );
102
105
$ buffer = fread ($ handle , $ chunkSize );
103
106
echo $ buffer ;
104
- @flush ();
105
- @ob_flush ();
106
107
}
107
108
fclose ($ handle );
108
- exit (( connection_status () == 0 ) && !connection_aborted ());
109
+ exit ( connection_status () == 0 && !connection_aborted ());
109
110
110
111
111
112
0 commit comments