Commit ed5f9795 authored by jiangkebao's avatar jiangkebao
Browse files

文件流下载

parent 1d22a338
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -850,3 +850,25 @@ if (!function_exists('download_file')) {
        return $path . '/' . $filename;;
    }
}

if (!function_exists('download_file_stream')) {

    /**文件流保存到本地
     * @param $fileStream 文件流
     * @param null $path 保存路径
     * @return string
     */
    function download_file_stream($fileStream, $path = null)
    {
        $root = config('server.settings.document_root', BASE_PATH . '/public');
        $path = $path ? $path : '/download/files';
        $savePath = $root . $path;
        if (!is_dir($savePath)) {
            // 判断路径是否存在,不存在,则创建
            mkdir($savePath, 0777, true);
        }
        $fileName = '/' . date('YmdHis') . 'track' . '.pdf';
        file_put_contents($savePath . $fileName, base64_decode($fileStream), 1);
        return $path . $fileName;
    }
}
 No newline at end of file