正在显示
1 个修改的文件
包含
93 行增加
和
0 行删除
up_pic.html
0 → 100644
1 | +<!DOCTYPE html> | ||
2 | +<html lang="en"> | ||
3 | +<head> | ||
4 | + <meta charset="UTF-8"> | ||
5 | + <title>Title</title> | ||
6 | +</head> | ||
7 | +<style> | ||
8 | + .file-box { | ||
9 | + position: relative; | ||
10 | + display: inline-block; | ||
11 | + } | ||
12 | + .file-box img { | ||
13 | + width: 50px; | ||
14 | + height: 50px; | ||
15 | + border-radius: 50%; | ||
16 | + top: -30px; | ||
17 | + left: 0; | ||
18 | + display: inline-block; | ||
19 | + border: none; | ||
20 | + } | ||
21 | + .file-box .txt,.file-box .file { | ||
22 | + width: 70px; | ||
23 | + height: 36px; | ||
24 | + top: -20px; | ||
25 | + left: 100px; | ||
26 | + text-align: center; | ||
27 | + } | ||
28 | +</style> | ||
29 | +<body> | ||
30 | +<div class="file-box"> | ||
31 | + <img id="preview" /> | ||
32 | + <input type="text" id="imgfield" class="txt" placeholder="预览"> | ||
33 | + <input type="file" name="file" id = "input_file" accept="image/gif,image/jpeg,image/jpg,image/png,image/svg" onchange="imgPreview(this)" > | ||
34 | +</div> | ||
35 | +<script type="text/javascript" src="js/jquery.min.js"> | ||
36 | + $(document).ready(function () { | ||
37 | + | ||
38 | + | ||
39 | + | ||
40 | + }) | ||
41 | + function imgPreview(fileDom) { | ||
42 | + alert(1) | ||
43 | + //判断是否支持FileReader | ||
44 | + if(window.FileReader) { | ||
45 | + var reader = new FileReader(); | ||
46 | + } else { | ||
47 | + alert("您的设备不支持图片预览功能,如需该功能请升级您的设备!"); | ||
48 | + } | ||
49 | + //获取文件 | ||
50 | + var file = fileDom.files[0]; | ||
51 | + var imageType = /^image\//; | ||
52 | + //是否是图片 | ||
53 | + if(!imageType.test(file.type)) { | ||
54 | + alert("请选择图片!"); | ||
55 | + return; | ||
56 | + } | ||
57 | + //读取完成 | ||
58 | + reader.onload = function(e) { | ||
59 | + alert(e) | ||
60 | + //获取图片dom | ||
61 | + var img = document.getElementById("preview"); | ||
62 | + //图片路径设置为读取的图片 | ||
63 | + img.src = e.target.result; | ||
64 | + | ||
65 | + | ||
66 | + var formData = new FormData(); | ||
67 | + formData.append('file', $('#input_file')[0].files[0]); //添加图片信息的参数 | ||
68 | + formData.append('sizeid',123); //添加其他参数 | ||
69 | + $.ajax({ | ||
70 | + url: '/material/uploadFile', | ||
71 | + type: 'POST', | ||
72 | + cache: false, //上传文件不需要缓存 | ||
73 | + data: formData, | ||
74 | + processData: false, // 告诉jQuery不要去处理发送的数据 | ||
75 | + contentType: false, // 告诉jQuery不要去设置Content-Type请求头 | ||
76 | + success: function (data) { | ||
77 | + var rs = eval("("+data+")"); | ||
78 | + if(rs.state==1){ | ||
79 | + tipTopShow('上传成功!'); | ||
80 | + }else{ | ||
81 | + tipTopShow(rs.msg); | ||
82 | + } | ||
83 | + }, | ||
84 | + error: function (data) { | ||
85 | + tipTopShow("上传失败"); | ||
86 | + } | ||
87 | + }) | ||
88 | + }; | ||
89 | + reader.readAsDataURL(file); | ||
90 | + } | ||
91 | +</script> | ||
92 | +</body> | ||
93 | +</html> |
-
请 注册 或 登录 后发表评论