base64图片文件上传实例
来源:互联网 发布:未来造价软件 编辑:程序博客网 时间:2024/05/22 02:13
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<title>jquery 图片base64</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<div id="testPhone" class="weui_uploader_input_wrp" style="width:79px; height:79px;">
</div>
<input id="testFile" type="file">
<hr>
<img id="testImg" style="max-height: 300px; height: 8em; min-width:8em;">
<hr>
<textarea id="testArea" style="display: block; width: 100%;height: 30em;"></textarea>
<input id="btnTest" type="button" value="提交base" />
<script>
$("#testPhone").click(function () {
$("#testFile").click();
});
$("#testFile").change(function () {
run(this, function (data) {
$('#testImg').attr('src', data);
$('#testArea').val(data);
});
});
$("#btnTest").click(function () {
$.ajax({
url: "",
type: "post",
dataType: "json",
data: {
"content": $("#testArea").val(),
},
async: false,
success: function (result) {
if (result.Code == 200) {
alert(result.Data);
} else {
}
}
});
});
function run(input_file, get_data) {
/*input_file:文件按钮对象*/
/*get_data: 转换成功后执行的方法*/
if (typeof (FileReader) === 'undefined') {
alert("抱歉,你的浏览器不支持 FileReader,不能将图片转换为Base64,请使用现代浏览器操作!");
} else {
try {
/*图片转Base64 核心代码*/
var file = input_file.files[0];
//这里我们判断下类型如果不是图片就返回 去掉就可以上传任意文件
if (!/image\/\w+/.test(file.type)) {
alert("请确保文件为图像类型");
return false;
}
var reader = new FileReader();
reader.onload = function () {
get_data(this.result);
}
reader.readAsDataURL(file);
} catch (e) {
alert('图片转Base64出错啦!' + e.toString())
}
}
};
</script>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width" />
<title>jquery 图片base64</title>
<script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
</head>
<body>
<div id="testPhone" class="weui_uploader_input_wrp" style="width:79px; height:79px;">
</div>
<input id="testFile" type="file">
<hr>
<img id="testImg" style="max-height: 300px; height: 8em; min-width:8em;">
<hr>
<textarea id="testArea" style="display: block; width: 100%;height: 30em;"></textarea>
<input id="btnTest" type="button" value="提交base" />
<script>
$("#testPhone").click(function () {
$("#testFile").click();
});
$("#testFile").change(function () {
run(this, function (data) {
$('#testImg').attr('src', data);
$('#testArea').val(data);
});
});
$("#btnTest").click(function () {
$.ajax({
url: "",
type: "post",
dataType: "json",
data: {
"content": $("#testArea").val(),
},
async: false,
success: function (result) {
if (result.Code == 200) {
alert(result.Data);
} else {
}
}
});
});
function run(input_file, get_data) {
/*input_file:文件按钮对象*/
/*get_data: 转换成功后执行的方法*/
if (typeof (FileReader) === 'undefined') {
alert("抱歉,你的浏览器不支持 FileReader,不能将图片转换为Base64,请使用现代浏览器操作!");
} else {
try {
/*图片转Base64 核心代码*/
var file = input_file.files[0];
//这里我们判断下类型如果不是图片就返回 去掉就可以上传任意文件
if (!/image\/\w+/.test(file.type)) {
alert("请确保文件为图像类型");
return false;
}
var reader = new FileReader();
reader.onload = function () {
get_data(this.result);
}
reader.readAsDataURL(file);
} catch (e) {
alert('图片转Base64出错啦!' + e.toString())
}
}
};
</script>
</body>
</html>
阅读全文
0 0
- base64图片文件上传实例
- base64编码上传图片java后台接收实例
- Android图片文件上传实例
- Android Base64上传图片
- php base64图片上传
- Base64上传图片
- 图片上传(Base64)
- 上传base64 图片
- iOS上传文件或base64(图片)之AFNetworking 3.0+上传文件上传图片
- php使用AjaxFileUpload上传图片文件实例
- iOS 图片base64编码 上传
- 上传base64图片无法显示
- Asp.net Base64图片上传
- 采用base64编码上传图片
- 上传base64格式的图片
- php下base64图片上传
- 上传base64图片到七牛云存储
- base64编码图片上传不了
- 爬虫学习笔记1——爬取糗百段子
- [Go]hello world
- 字符串输入、输出
- HDU
- 从豆瓣电影评分算法说起
- base64图片文件上传实例
- Qt之QLabel
- CentOS7使用firewalld控制防火墙,以及使用iptables设置
- 理解OAuth 2.0
- PopupWindow简单实现
- zabbix java api
- 如何使用jstack分析线程状态
- 文章标题
- 实验一线性表的基本操作实现及其应用