JQ、AJAX、THINKPHP实现文件上传

浏览:3531 发布日期:2017/03/24 分类:技术分享 关键字: jq ajax thinkphp
<html>
<head>
<title>利用JQuery的ajax请求实现文件上传</title>
<script src=”__PUBLIC__/js/jquery-1.7.2.min.js”></script>
<script src=”__PUBLIC__/js/ajaxfileupload.js”></script>
</head>
<body>
<input type=”file” name=”file1″ id=”file1″/>
<button type=”button” id=”submitId”>点击上传</button>

<script>
$(“#submitId”).on(“click”,function () {
$.ajaxFileUpload({
url:”{:U(‘Upload/yes’)}”, //你处理上传文件的服务端
secureuri:false,//是否启用安全机制
fileElementId:’file1′,//file的id
dataType: ‘application/json’,//返回的类型
success: function (data) {
alert(“上传成功”);
}
});
})
</script>
</body>
</html>





<?php
namespace Home\Controller;
use Think\Controller;
class UploadController extends Controller {
public function index(){

$this->display();
}
public function yes(){

if($_FILES){
echo 1;

}else{
echo 2;
}
}

}
文件下载地址:http://www.momoyingyu.com/blog/archives/401
最佳答案
评论( 相关
后面还有条评论,点击查看>>