图片上传 小咪咪 2022-06-01 14:24 265阅读 0赞 # html # <button type="button" class="btn btn-primary" οnclick="F\_Open\_dialog2()">Import</button> <input type="file" id="btn\_file2" style="display: none" onChange="imgview(this)" /> # js # function F\_Open\_dialog2() \{ document.getElementById("btn\_file2").click(); \} function imgview(ths ) \{ // 判断图片格式是否合格 var filepath = document.getElementById(ths.id).value; var re = /(\\\\+)/g; var filename = filepath.replace(re, "\#"); var one = filename.split("\#"); var two = one\[one.length - 1\]; var imgName = two.split("."); var suffix = imgName\[imgName.length - 1\]; var tp = "jpg,gif,png,JPG,GIF,PNG"; var rs = tp.indexOf(suffix); var id = $(ths).parent().prev().attr("id"); if (rs >= 0) \{ var fileObj = $(ths)\[0\].files\[0\]; var formData = new FormData(); formData.append("file", fileObj); $.ajax(\{ url : '/gtm/rest/fileservice/photo' , type : 'POST' , data : formData , success : function(data, status ) \{ if (data != null) \{ var nextinp = $(ths).nextAll('img')\[0\]; $(nextinp).attr("src",data) $($(ths).nextAll('input')\[0\]).val(data) \} \} , error : function(data, status, e ) \{ \} , cache : false , contentType : false , processData : false \}); return true; \} else \{ ths.html("") return false; \} \} # java # @POST @Path("photo") @Consumes(MediaType.MULTIPART\_FORM\_DATA) public String uploadPhoto(@FormDataParam("file") InputStream fileInputStream, @FormDataParam("file") FormDataContentDisposition disposition) \{ if (fileInputStream != null) \{ String path = fileService.savePhoto(fileInputStream,request.getSession().getServletContext().getRealPath("/")+"img\\\\userPto\\\\"); return path; \} return null; \} public String savePhoto(InputStream fileInputStream, String pathHead) \{ //将时间作为图片名 String imageName = System.currentTimeMillis() + ".jpg"; String newPath = UPLOADPATH + imageName; String result = PATH + imageName; OutputStream fop = null; File file; try \{ //创建文件 file = new File(newPath); fop = new FileOutputStream(file); if (!file.exists()) \{ file.createNewFile(); \} int read = 0; byte\[\] bytes = new byte\[1024\]; //写文件 while ((read = fileInputStream.read(bytes)) != -1) \{ fop.write(bytes, 0, read); \} fop.flush(); \} catch (IOException e) \{ e.printStackTrace(); \} finally \{ try \{ if (fop != null) \{ fop.close(); \} return result; \} catch (IOException e) \{ e.printStackTrace(); \} \} return null; \}
相关 apiclod 上传图片_apiCloud上传图片 Hello APP height:100%; \} \wrap\{ height:100%; display:-webkit-box; display:-webki 野性酷女/ 2022年10月31日 00:57/ 0 赞/ 247 阅读
相关 图片上传 [AngularJS图片上传功能的实现][AngularJS] 一、前言 前一段时间做项目时,遇到一个问题就是AngularJS实现图片预览和上传的功能,当时查阅文档(都是 痛定思痛。/ 2022年06月05日 00:48/ 0 赞/ 232 阅读
相关 图片上传 上篇博客已经介绍了文件的上传,这次就简单总结一下图片的上传,以及上传图片的显示。 利用三个控件:Input(File)、Button控件、Image控件,页面简单设计如下图: 川长思鸟来/ 2022年06月03日 08:26/ 0 赞/ 229 阅读
相关 图片上传 1, 定义模型 class UserLearn(models.Model): u_name = models.CharField(max_length=16) u_i 缺乏、安全感/ 2022年06月03日 02:27/ 0 赞/ 246 阅读
相关 图片上传 html <button type="button" class="btn btn-primary" οnclick="F\_Open\_dialog2()">Impor 小咪咪/ 2022年06月01日 14:24/ 0 赞/ 266 阅读
相关 图片上传 文件上传流程: 1、定义 <input type="file" name="file" accept="image/\" onchange="uploadimage(th ゝ一世哀愁。/ 2022年04月02日 11:46/ 0 赞/ 326 阅读
相关 上传图片 开发工具与关键技术:Visual Studio 作者:肖广斌 撰写时间:2019年5月12日 在做项目时,我们在完善一些个人信息、或者一些页面时,我们需要用到图片, 本是古典 何须时尚/ 2022年01月31日 12:45/ 0 赞/ 295 阅读
相关 上传图片 @Service public class FileServiceImpl implements FileService { privat 柔情只为你懂/ 2021年12月23日 13:47/ 0 赞/ 385 阅读
相关 上传图片 <img src="~/Content/img/btn\_1.png" class="img-responsive" id="a\_pic"> <input class=" £神魔★判官ぃ/ 2021年09月30日 09:54/ 0 赞/ 578 阅读
相关 上传图片 // 允许上传的图片后缀 $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = expl 蔚落/ 2021年09月18日 22:22/ 0 赞/ 513 阅读
还没有评论,来说两句吧...