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

景德镇网站制作千峰培训多少钱

景德镇网站制作,千峰培训多少钱,dede推荐评级网站模版,网站建设愿景之前测试功能写过一次,因为代码忘记保存,导致真正用到的时候怎么也想不起来当初怎么写的了,复现后还是写个文章记录一下,省的下次再忘记。 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.yidumall.com/news/43982.html

相关文章:

  • 深圳做网站制作抖音seo排名系统
  • 如何用wordpress建一个网站百度网页电脑版入口
  • 网站上传文件大小限制淮北网站建设
  • 做微网站的公司外贸营销型网站制作公司
  • 2017网站建设前景怎么开发网站
  • 网站设计实施方案销售管理系统
  • 程序开发语言有哪些山东进一步优化
  • 一图读懂制作网站电商平台推广公司
  • 网站建设推进表怎么推广app让人去下载
  • 国外真正的永久免费建站app注册推广团队
  • 深圳做网站公浏览器谷歌手机版下载
  • 中国风html5网站模板免费下载seo综合查询
  • 贵阳市网站建设公司百度seo优化方法
  • 攻击自己做的网站网络营销课程思政
  • 桥头仿做网站独立网站怎么做
  • 营销型网站建设遨龙软文推广代写代发
  • 培训机构倒闭seo人员工作内容
  • 陕西十二建设有限公司网站百度搜索大全
  • 重庆无障碍网站建设上海热点新闻
  • 自己做的网站服务器开了进不去bt磁力猪
  • 广东建设监理协会网站题库重庆百度搜索优化
  • 广西住房城乡建设网站一个产品的营销方案
  • 重庆做网站推广广东seo推广公司
  • 网站进度条代码如何百度推广
  • 自己做蛋糕有什么网站吗软件培训班学费多少
  • 广州注册个体户流程及费用网站seo搜索引擎优化案例
  • 湖北工程造价信息网seo推广的网站和平台有哪些
  • 做国外网站什么好赣州seo推广
  • 深圳乐安居网站谁做的南宁白帽seo技术
  • 做网站空间备案的职业sem网络营销