31
31
* - `id` The filename on the server's filesystem, including extension.
32
32
* - `name` The filename that will be sent to the user, specified without the extension.
33
33
* - `download` Set to true to set a `Content-Disposition` header. This is ideal for file downloads.
34
- * - `extension` The extension of the file being served. This is used to set the mimetype
34
+ * - `extension` The extension of the file being served. This is used to set the mimetype.
35
+ * If not provided its extracted from filename provided as `id`.
35
36
* - `path` The absolute path, including the trailing / on the server's filesystem to `id`.
36
37
* - `mimeType` The mime type of the file if CakeResponse doesn't know about it.
38
+ * Must be an associative array with extension as key and mime type as value eg. array('ini' => 'text/plain')
37
39
*
38
40
* ### Usage
39
41
*
@@ -113,7 +115,11 @@ public function render($view = null, $layout = null) {
113
115
$ this ->response ->type ($ mimeType );
114
116
}
115
117
116
- if (isset ($ extension ) && $ this ->_isActive ()) {
118
+ if (!isset ($ extension )) {
119
+ $ extension = pathinfo ($ id , PATHINFO_EXTENSION );
120
+ }
121
+
122
+ if ($ this ->_isActive ()) {
117
123
$ extension = strtolower ($ extension );
118
124
$ chunkSize = 8192 ;
119
125
$ buffer = '' ;
@@ -128,7 +134,7 @@ public function render($view = null, $layout = null) {
128
134
} else {
129
135
$ modified = time ();
130
136
}
131
- if ($ this ->response ->type ($ extension ) === false ) {
137
+ if (! $ extension || $ this ->response ->type ($ extension ) === false ) {
132
138
$ download = true ;
133
139
}
134
140
@@ -157,6 +163,8 @@ public function render($view = null, $layout = null) {
157
163
}
158
164
if (is_null ($ name )) {
159
165
$ name = $ id ;
166
+ } elseif ($ extension ) {
167
+ $ name .= '. ' . $ extension ;
160
168
}
161
169
$ this ->response ->download ($ name );
162
170
$ this ->response ->header (array ('Accept-Ranges ' => 'bytes ' ));
0 commit comments