bootstrap上传照片

图片.png

实际项目中运用:
图片.png

功能:实现上传图片,更改上传图片,移除图片的功能

<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
		<link rel="stylesheet" href="bootstrap-fileinput.css">
		<script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
		<script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
		<script src="bootstrap-fileinput.js"></script>
	</head>

	<body>
		<div class="form-group">
			<div class="col-md-8">
				<div class="fileinput fileinput-new" data-provides="fileinput" id="uploadImageDiv">
					<div class="fileinput-new thumbnail" style="width: 200px; height: 150px;">
						<img src="${companyInfo.image}" alt="" />
					</div>
					<div class="fileinput-preview fileinput-exists thumbnail" style="max-width: 200px; max-height: 150px;"></div>
					<div>
						<span class="btn default btn-file"> <span
											class="fileinput-new">选择图片</span> <span class="fileinput-exists">更改</span> <input type="file" name="uploadImage" id="uploadImage" /></span>
						<a href="#" class="btn default fileinput-exists" data-dismiss="fileinput">移除</a>
						<span>请选择1M以内图片</span>
					</div>
				</div>
				<div id="titleImageError" style="color: #a94442"></div>
			</div>
		</div>
	</body>
	 <script>
       var url = '';
$("#uploadImage").fileupload({
	url : ROOT + "/security/company/uploadFile",
	dataType : 'json',
	autoUpload : false,
	acceptFileTypes : /(gif|jpe?g|png)$/i,
	maxFileSize : 1000000, // 1 MB
	imageMaxWidth : 100,
	imageMaxHeight : 100,
	messages : {
		acceptFileTypes : '文件类型不匹配',
		maxFileSize : '文件过大',
		minFileSize : '文件过小'
	}
}).on("fileuploadadd", function(e, data) {
	// 当文件添加上去时候调用
	$("#titleImageError").html("");
	data.submit()
}).on("fileuploaddone", function(e, data) {
	// 上传完成时调用
	if (data.result.returnState == "ERROR") {
		alert("上传失败")
		return;
	}
	url = data.result.returnData.url;
});

function updateMsg() {
	$.ajax({
		url : ROOT + "/security/company/updateInfo",
		data : {
			id : $("#companyId").val(),
			image : url,
			companyName : $("#companyName").val(),
			companySite : $("#companySite").val(),
			companyLinker : $("#companyLi
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值