77 * @license MIT
88 */
99
10+ namespace Apfelbox \FileDownload ;
11+
12+ use Skyzyx \Components \Mimetypes \Mimetypes ;
1013
1114/**
1215 * Provides a simple way to create file downloads in PHP
@@ -27,13 +30,13 @@ class FileDownload
2730 *
2831 * @param resource $filePointer
2932 *
30- * @throws InvalidArgumentException
33+ * @throws \ InvalidArgumentException
3134 */
3235 public function __construct ($ filePointer )
3336 {
3437 if (!is_resource ($ filePointer ))
3538 {
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 " );
3740 }
3841
3942 $ this ->filePointer = $ filePointer ;
@@ -81,20 +84,11 @@ public function sendDownload ($filename)
8184 */
8285 private function getMimeType ($ fileName )
8386 {
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 " ;
9892 }
9993
10094
0 commit comments