<?php
if(isset($_FILES['upfile'])){
$arr_ext = explode('.', $_FILES["upfile"]["name"]);
$path = "./Uploads/".date('Ymd').'/';
if(!is_dir($path)){
mkdir($path,0777,true);
}
$file_path = $path.uniqid().'.'.$arr_ext[1];
//复制图片
if(move_uploaded_file($_FILES["upfile"]["tmp_name"], $file_path)){
$this->ajaxReturn(array('ok'));
}else{
$this->ajaxReturn(array('fail'));
}
}
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
<script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js" ></script>
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- 可选的 Bootstrap 主题文件(一般不用引入) -->
<link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<body>
<div class="container">
<h1>添加员工操作</h1>
<div class="col-md-6">
<form action="" method='POST' enctype='multipart/form-data' id="form">
<div class="form-group">
<label for="exampleInputFile">上传头像</label>
<input type="file" name="log" id="file_img" >
</div>
</form>
</div>
</div>
</body>
</html>
<script>
$(function(){
$('#file_img').change(function(){
var fd = new FormData();
fd.append("upfile", $("#file_img").get(0).files[0]);
$.ajax({
url:'__CONTROLLER__/uploadTofile',
type:"post",
processData: false,
contentType: false,
data:fd,
success:function(){
}
});
});
})
</script>
jq ajax 异步上传文件
最新推荐文章于 2024-07-29 20:46:57 发布