企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
* [ ] 浏览器输出文件内容 ``` Response::SendData($FileData, $Format = null); ``` FilePlace(string|array):内容 Format (string|bool):格式=显示,文件名=下载 ***** 输出验证码例,自动加上mime ``` $data = Frame::ObStart(function () use ($int) { self::ImgCode(); }); Response::SendData($data, 'jpg'); ``` 验证码下载例,自动加上mime ``` $data = Frame::ObStart(function () use ($int) { self::ImgCode(); }); Response::SendData($data, 'code.jpg'); ``` 输出验证码,自定义mime ``` $data = Frame::ObStart(function () use ($int) { self::ImgCode(); }); Response::SendData([$data,'image/jpeg']); ``` 下载验证码,自定义mime ``` $data = Frame::ObStart(function () use ($int) { self::ImgCode(); }); Response::SendData([$data,'image/jpeg'],'code.jpg'); ``` ``` private static function ImgCode($num = 5, $codes = 'code_name', $w = 60, $h = 20, $str = '') { $str = !empty ($str) ? $str : 'abcdefghkmnprstuvwxyzABCDEFGHKMNPRSTUVWXYZ23456789'; $code = ''; for ($i = 0; $i < $num; $i++) { $code .= $str [mt_rand(0, strlen($str) - 1)]; } $im = imagecreate($w, $h); $_bg = imagecolorallocate($im, 255, 255, 255); imagefilledrectangle($im, 0, 0, $w, $h, $_bg); $gray = imagecolorallocate($im, 204, 213, 204); imagerectangle($im, 0, 0, $w - 1, $h - 1, $gray); $rand_ = imagecolorallocate($im, 204, 213, 204); for ($i = 0; $i < 80; $i++) { imagesetpixel($im, rand(0, $w), rand(0, $h), $rand_); } $black = imagecolorallocate($im, 0, 0, 204); $_str = ($w - 40) / 2; for ($i = 0; $i < $num; $i++) { imagestring($im, 5, $_str, ($h - 16) / 2, substr($code, $i, 1), $black); $_str += 10; } imagepng($im); imagedestroy($im); } ```