前台代码
<!DOCTYPE html>
<html>
<head>
<me
<ti
<load href="__PUBLIC__/Css/basic.css" />
<load href="__PUBLIC__/Css/Home/reg.css" />
<load href="__PUBLIC__/Js/jquery.js"/>
</head>
<body>
<form action="{:U('fileup')}" method='post' enctype='multipart/form-data'>
<input type="file" name='file' id='pic1' >
<input type='text' name='filename'>
<input type="submit" value='提交'>
</form>
<sc
$(document).ready(function(){
$("#pic1").live("change", function () {
$.ajax({
url:"__URL__/fileup1",
data: {'pic1':$(this).val()},
type:"post",
success: function (data) {
alert(data);
}
});
});
});
</sc
</body>
</html>
后台控制器
public function fileup1(){
$pic1=$_POST['pic1'];
$config = array(
'maxSize' => 3145728,
'savePath' => '/', //此处的路径会自动在根目录的Uploads下建立
'saveName' => array('date','YmdHms'),
'exts' => array('exe','jpg', 'gif', 'png', 'jpeg'),
'autoSub' => true,
);
$upload = new \Think\Upload($config);// 实例化上传类
$info = $upload->uploadOne($pic1); //此处需要注意的是这里的dilename是表单的name
$this->ajaxReturn($info,'json');
}
最佳答案