/** * 处理下载文件逻辑 */ private function downloadFile() { $file_name = $_POST["Filename"]; $key = $_POST["key"]; $path = ''; // 参数检查 if (strlen(trim($file_name)) <= 0 || strlen(trim($key)) <= 0) { Yii::log(Yii::t('api', "Request is Error, file_name:'{$file_name}'"), CLogger::LEVEL_ERROR, "miniyun.api"); throw new MException(Yii::t('api', MConst::FILE_NOT_EXIST), MConst::DOWNLOAD_FILE_FAILS); } // 全路径 $path = str_replace("\${filename}", $file_name, $key); if (is_null($path) || strlen(trim($path)) <= 0) { Yii::log(Yii::t('api', "Request is Error, file_name:'{$file_name}'"), CLogger::LEVEL_ERROR, "miniyun.api"); throw new MException(Yii::t('api', MConst::FILE_NOT_EXIST), MConst::DOWNLOAD_FILE_FAILS); } $file_path = DOCUMENT_ROOT_BLOCK . $path; //文件不存在 if (file_exists($file_path) == false) { Yii::log(Yii::t('api', "File do not exist, path:'{$file_path}'"), CLogger::LEVEL_ERROR, "miniyun.api"); throw new MException(Yii::t('api', MConst::FILE_NOT_EXIST), MConst::DOWNLOAD_FILE_FAILS); } $content_type = 'application/force-download'; MUtils::download($file_path, $content_type, $file_name); }