当前位置: 首页 > news >正文

莱西网站制作百度识图找原图

莱西网站制作,百度识图找原图,哪个新闻网站做的好,网站开发用php还是.net好之前测试功能写过一次,因为代码忘记保存,导致真正用到的时候怎么也想不起来当初怎么写的了,复现后还是写个文章记录一下,省的下次再忘记。 php后端 /*** 图片保存到本地*/ public function uploadLocalImage() {try {$img $thi…

之前测试功能写过一次,因为代码忘记保存,导致真正用到的时候怎么也想不起来当初怎么写的了,复现后还是写个文章记录一下,省的下次再忘记。

php后端

/*** 图片保存到本地*/
public function uploadLocalImage()
{try {$img = $this->_request->file('img');if (empty($img)) {throw new \Exception('缺少图片参数');}$writeDir = "images/".date('Ymd');$dir = "D:/phpstudy_pro/WWW/vkm_locarun_dist/dist/".$writeDir;//$dir = "local_run/" . date('Ymd'); //linux调试地址if (!file_exists($dir)) {mkdir($dir, 0777, true);}$extension = substr($img->getMimeType(), -3);if ($extension == 'bmp') {$fileName = UtilService::createOrderNo() . '.bmp';}if ($extension == 'png') {$fileName = UtilService::createOrderNo() . '.png';}else{$fileName = UtilService::createOrderNo() . '.jpg';}$imgContent = file_get_contents($img);file_put_contents($dir . '/' . $fileName, $imgContent);$localhostImg = env('CLIENT_URL') . $writeDir . '/' . $fileName;//http://127.0.0.1:8000/xxx/20231016/xxx.jpg 读取方式$this->returnSuccess($localhostImg);} catch (\Exception $e) {$this->returnFault($e->getMessage());}
}

Unity C#

/// <summary>
/// 上传文件到服务器
/// </summary>
/// <param name="filePaths">文件路径</param>
void UploadToLocalServer(string[] filePaths)
{int count = filePaths.Length;urls = new string[count];isUploaded = new bool[count];string filePath;//文件命为上传OSS时的keyfor (int i = 0; i < count; i++){int current = i;filePath = filePaths[current];if (File.Exists(filePath)){File.SetAttributes(filePath, FileAttributes.Normal);StartCoroutine(UploadToLocal(filePath, current));}else{urls[current] = "none";}}
}
IEnumerator UploadToLocal(string filePath, int index)
{byte[] fileByte = File.ReadAllBytes(filePath);WWWForm form = new WWWForm();//根据自己上传的文件修改格式,img是接口请求json参数的key, //最后一个参数是图片的mimeType, 因为上传的图片有jpg、png、bmp几种格式,此处取文件后缀和image组合字符串作为mimeTypeform.AddBinaryData("img", fileByte, Path.GetFileName(filePath), $"image/{Path.GetExtension(filePath)}");Helper.Log($"{Config.SystemConfig.sendHost}/uploadLocalImage");using (UnityWebRequest www = UnityWebRequest.Post($"{Config.SystemConfig.sendHost}/uploadLocalImage", form)){yield return www.SendWebRequest();if (www.result == UnityWebRequest.Result.ConnectionError || www.result == UnityWebRequest.Result.ProtocolError){urls[index] = "error";Helper.LogError($"[ERROR] {filePath}, msg: {www.error}");}else{string text = www.downloadHandler.text;//Helper.Log("服务器返回值" + text);JObject json = JObject.Parse(text);if (json["msg"].ToString().Equals("success")){urls[index] = json["data"].ToString();Helper.Log($"[SUCCESS] {urls[index]}");}else{urls[index] = "error";Helper.LogError($"[ERROR] {filePath}, msg: {text}");}isUploaded[index] = true;}}
}

搞定。

http://www.ritt.cn/news/15771.html

相关文章:

  • 网站开发和网络工程哪个好企业查询app
  • 招聘网站如何做SEO合肥关键词排名优化
  • 响应式web开发项目教程常州seo
  • 网站维护怎么做天眼查企业查询入口
  • 网站正在建设中页面下载百度云盘网页版
  • 宠物网站模板长春做网站公司长春seo公司
  • 北京市通州区住房和城乡建设委员会网站西安网站推广助理
  • 06627网页制作和网站建设试卷查询网址域名ip地址
  • 王者荣耀做网站seo网站优化论文
  • 深圳做网站网络公司怎么样app拉新渠道
  • 商务网站建设与维护测试题答案windows优化大师绿色版
  • 上海市网站开发搜狗推广登录
  • 石景山网站建设的大公司网络营销的实现方式
  • 沈阳微网站建设网站推广优化之八大方法
  • 网站建设的博客seo综合排名优化
  • 深圳专业企业网站制作百度云搜索引擎入口 百度网盘
  • 网站 会员系统 织梦百度线上推广
  • 自己怎样做公司广告视频网站百度一下手机版
  • jsp网站开发 心得seo优化主要做什么
  • 做淘宝还是做网站网站建成后应该如何推广
  • 小苹果活动代做网站免费seo网站
  • 助农网站策划书b站2023年免费入口
  • 做网站上传电子书男生最喜欢的浏览器推荐
  • 官方网站的英文html网页制作模板
  • 网站访问统计方案昆明网络营销
  • 棠下手机网站建设电话网络销售怎么聊客户
  • 海外贸易在什么网站做百度秒收录软件工具
  • 官网建站合作模版免费平台推广
  • 网站群建设存在的问题推送者seo
  • 网站首页标题阿里云网站搭建