/** * Determines the MIME type based on the extension name of the specified file. * This method will use a local map between extension names and MIME types. * * @param string $fileName the file name. * @return string the MIME type. Null is returned if the MIME type cannot be determined. */ public function getMimeType($fileName) { return MimeType::getMimeType($fileName); }
/** * 发送文件到浏览器 * * @param string $filePath the path of the file to be sent. * @param string $attachmentName the file name shown to the user. If null, it will be determined from `$filePath`. * @param array $options additional options for sending the file. The following options are supported: * * - `mimeType`: the MIME type of the content. If not set, it will be guessed based on `$filePath` * - `inline`: boolean, whether the browser should open the file within the browser window. Defaults to false, * meaning a download dialog will pop up. * * @return static the response object itself */ public function sendFile($filePath, $attachmentName = null, $options = []) { if (!isset($options['mimeType'])) { $options['mimeType'] = MimeType::getMimeType($filePath); } if ($attachmentName === null) { $attachmentName = basename($filePath); } $handle = fopen($filePath, 'rb'); $this->sendStreamAsFile($handle, $attachmentName, $options); return $this; }