php+ajax+h5实现ajax图⽚上传html页⾯代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="__PUBLIC__/home/js/jquery-1.11.0.js"></script>
</head>
<body>
<form class="form-horizontal" role="form" id="myForm"
action="/index/fileupsend" method="post"
enctype="multipart/form-data">
选择⽂件:<input type="file" id="file1" /><br />
<input type="button" id="upload" value="上传" />
<span id="imgWait"></span>
</form>
<script>
$(function () {
$("#upload").click(function () {
$("#imgWait").html("上传中");
var formData = new FormData();
formData.append("myfile", ElementById("file1").files[0]);
$.ajax({
url: "/Home/index/fileupsend",
type: "POST",
data: formData,
/**
*必须false才会⾃动加上正确的Content-Type
*/
contentType: false,
/**
* 必须false才会避开jQuery对 formdata 的默认处理
* XMLHttpRequest会对 formdata 进⾏正确的处理
*/
processData: false,jquery实现ajax
success: function (data) {
if(data){
alert("上传成功!");
}
$("#imgWait").html("上传成功");
},
error: function () {
alert("上传失败!");
$("#imgWait").hide();
}
});
});
});
</script>
</body>
</html>
php代码
public function fileupsend(){
$type_pic = $this->file_upload('1',array('jpg', 'gif', 'png', 'jpeg'),'filetest','myfile');
echo $type_pic['img_path'];
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。