html:
<!DOCTYPE html>
<html>
<include file="Public/header" />
<link rel="stylesheet" href="__WECHAT__/css/aui.css" />
<link rel="stylesheet" href="__WECHAT__/css/weui.min.css" />
</head>
<style>
.weui-cell{padding:1.5px 15px!important;}
</style>
<body>
<div class="weui-cells weui-cells_form">
<form action="{:U('Demo/ceshi')}" method="post" class="form-horizontal js-ajax-forms" enctype="multipart/form-data">
<div class="weui-bd">
<div class="weui-cell">
<div class="weui-cell__hd">
<label for="info_photo" class="col-sm-2 control-label">物品圖片</label>
</div>
<div class="weui-cell__bd">
<span class="btn btn-success btn-file">
<input type="file" class="weui-input" required="required" name="info_photo" value="" id="info_photo"
onchange='PreviewImage(this)' />
</span>
</div>
</div>
<div class="weui-cell">
<div class="weui-cell__hd">
<div id="photo_info" class="photo_info"></div>
</div>
</div>
<a class="weui-cell weui-cell_access">
<div class="submit">
<input type="submit" id="txt" style="color:#fff;background:none;font-size:15px;" value="注冊"/>
</div>
</a>
</div>
</form>
</div>
<div class="weui-footer">
<p class="weui-footer__text">Copyright © 2008-2016 工傷鏢局</p>
</div>
<script type="text/javascript" src="__JS__/jquery-3.1.0.min.js"></script>
<script type="text/javascript">
function clickButton(obj){
var phone=$("input[name='phone']").val();
$.post({
url: "{:U('Demo/sendMsg')}",
type: "post",
data: {
phone:phone,
},
dataType: "json",
success: function(data){
}
});
var obj = $(obj);
obj.attr("disabled","disabled");/*按鈕倒計時*/
var time = 60;
var set=setInterval(function(){
obj.val(--time+"(s)");
}, 1000);/*等待時間*/
setTimeout(function(){
obj.attr("disabled",false).val("重新獲取驗證碼");/*倒計時*/
clearInterval(set);
}, 60000);
}
</script>
<script type="text/javascript">
<!-- 對比兩次輸入的密碼 -->
function validate() {
var pwd1 = document.getElementById("pwd1").value;
var pwd2 = document.getElementById("pwd2").value;
if(pwd1 == pwd2) {
document.getElementById("tishi").innerHTML="<font color='green'>兩次密碼相同</font>";
}
else {
document.getElementById("tishi").innerHTML="<font color='red'>兩次密碼不相同</font>";
}
}
</script>
<script type="text/javascript">//上傳圖片立即預(yù)覽
function PreviewImage(imgFile) {
var filextension = imgFile.value.substring(imgFile.value
.lastIndexOf("."), imgFile.value.length);
filextension = filextension.toLowerCase();
if ((filextension != '.jpg') && (filextension != '.gif')
&& (filextension != '.jpeg') && (filextension != '.png')
&& (filextension != '.bmp')) {
alert("對不起,系統(tǒng)僅支持標(biāo)準(zhǔn)格式的照片,請您調(diào)整格式后重新上傳樱哼,謝謝 !");
imgFile.focus();
} else {
var path;
if (document.all)//IE
{
imgFile.select();
path = document.selection.createRange().text;
document.getElementById("photo_info").innerHTML = "";
document.getElementById("photo_info").style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(enabled='true',sizingMethod='scale',src=\""
+ path + "\")";//使用濾鏡效果
} else//FF
{
path = window.URL.createObjectURL(imgFile.files[0]);// FF 7.0以上
//path = imgFile.files[0].getAsDataURL();// FF 3.0
document.getElementById("photo_info").innerHTML = "<img id='img1' width='120px' height='100px' src='"+path+"'/>";
//document.getElementById("img1").src = path;
}
}
}
</script>
</body>
</html>
PHP:
public function ceshi()
{
$img=is_uploaded_file($_FILES['info_photo']['tmp_name']);
//如果有上傳文件轮听,獲取新文件id
if($img){
$upload = new \Think\Upload();// 實例化上傳類
$upload->maxSize = 5*1024*1024 ;// 設(shè)置附件上傳大小
$upload->exts = array('jpg', 'gif', 'png', 'jpeg','bmp');// 設(shè)置附件上傳類型
$upload->rootPath = './public'; // 設(shè)置附件上傳根目錄
$upload->savePath = '/upload/'; // 設(shè)置附件上傳(子)目錄
// 上傳文件
$f=$_FILES['info_photo'];
$imginfo = $upload->uploadOne($f);
if(!$imginfo) {
$error="上傳圖片失敗".$upload->getError();
}else{
$idata=$imginfo['savepath'].$imginfo['savename'];
dump($idata);die;
}
}
}