7
7
* @license MIT
8
8
*/
9
9
10
+ namespace Apfelbox \FileDownload ;
11
+
12
+ use Skyzyx \Components \Mimetypes \Mimetypes ;
10
13
11
14
/**
12
15
* Provides a simple way to create file downloads in PHP
@@ -27,13 +30,13 @@ class FileDownload
27
30
*
28
31
* @param resource $filePointer
29
32
*
30
- * @throws InvalidArgumentException
33
+ * @throws \ InvalidArgumentException
31
34
*/
32
35
public function __construct ($ filePointer )
33
36
{
34
37
if (!is_resource ($ filePointer ))
35
38
{
36
- throw new InvalidArgumentException ("You must pass a file pointer to the ctor " );
39
+ throw new \ InvalidArgumentException ("You must pass a file pointer to the ctor " );
37
40
}
38
41
39
42
$ this ->filePointer = $ filePointer ;
@@ -81,20 +84,11 @@ public function sendDownload ($filename)
81
84
*/
82
85
private function getMimeType ($ fileName )
83
86
{
84
- switch (pathinfo ($ fileName , PATHINFO_EXTENSION ))
85
- {
86
- case "pdf " : return "application/pdf " ;
87
- case "exe " : return "application/octet-stream " ;
88
- case "zip " : return "application/zip " ;
89
- case "doc " : return "application/msword " ;
90
- case "xls " : return "application/vnd.ms-excel " ;
91
- case "ppt " : return "application/vnd.ms-powerpoint " ;
92
- case "gif " : return "image/gif " ;
93
- case "png " : return "image/png " ;
94
- case "jpeg " :
95
- case "jpg " : return "image/jpg " ;
96
- default : return "application/force-download " ;
97
- }
87
+ $ fileExtension = pathinfo ($ fileName , PATHINFO_EXTENSION );
88
+ $ mimeTypeHelper = Mimetypes::getInstance ();
89
+ $ mimeType = $ mimeTypeHelper ->fromExtension ($ fileExtension );
90
+
91
+ return !is_null ($ mimeType ) ? $ mimeType : "application/force-download " ;
98
92
}
99
93
100
94
0 commit comments