你的浏览器禁用了JavaScript, 请开启后刷新浏览器获得更好的体验!
输入关键字进行搜索
搜索:
没有找到相关结果
dolphinphp
赞同来自: laozhu1986
$pic = $this->request->post('pic'); // 假设这是接收过来的base64图片数据 if (preg_match('/^(data:\s*image\/(\w+);base64,)/', $pic, $result)){ $file_type = $result[2]; // 图片后缀 $file_content = $result[1]; // 图片内容 $file_name = md5($pic) . '.'.$file_type; // 保存图片名 $dir = config('upload_path') . DS . 'images' . DS . date('Ymd', $this->request->time()); $file_path = $dir . DS . $file_name; if (!is_dir($dir)) { mkdir($dir, 0755, true); } // 将base64图片保存到服务器 if (false === file_put_contents($file_path, base64_decode(str_replace($file_content, '', $signature)))){ $this->error('上传出错'); }else{ // 打开已保存的图片 $file = new File($file_path); // 附件上传钩子,用于第三方文件上传扩展 if (config('upload_driver') != 'local') { $hook_result = Hook::listen('upload_attachment', $file, ['from' => '', 'module' => $this->request->module()], true); if (false !== $hook_result) { return $hook_result; } } else { $file_info = [ 'uid' => session('user_auth.uid'), 'name' => $file_name, 'mime' => 'image/png', 'path' => 'uploads/images/' . date('Ymd', $this->request->time()) . '/' . $file_name, 'ext' => 'png', 'size' => $file->getSize(), 'md5' => $file->hash('md5'), 'sha1' => $file->hash('sha1'), 'module' => $this->request->module() ]; // 写入数据库 $result = AttachmentModel::create($file_info); if ($result) { return json([ 'code' => 1, 'info' => '上传成功', 'id' => $result['id'], 'path' => $result['path'] ]); } else { return json([ 'code' => 0, 'info' => '上传失败' ]); } } } }
laozhu1986
赞同来自:
要回复问题请先登录或注册
2 个回复
dolphinphp
赞同来自: laozhu1986
比如
laozhu1986
赞同来自: