html上传压缩包后台PHP处理
作者:互联网
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<div class="form-group">
<div class="col-sm-2">
<button type="button" style="width:124px;" class="btn btn-info pull-left">其他附件</button>
</div>
</div>
<div class="form-group">
<label for="touxiang" class="col-sm-2 control-label"> 其他附件
</label>
<div class="col-sm-6">
<input id="harg_file" type="file" accept="application/zip"/>
<input name="fileurl" type="hidden" id="fileurl" value="">
<div id="upshow" style="border:#666 1px solid;padding:0px;height:27px;width:202px">
<p id="upload_tip" style="margin:0xp;height:25px;width:0px; background-color:#390; text-align:center;color:#FFF;"></p></div>
</div>
</div>
</body>
</html>
<script>
$(document).ready(function(e) {
$("#harg_file").change(function(){
var fd=new FormData();
if($(this).get(0).files[0].size>15728640){
alert("附件不能大于15M,附件为zip、rar、jpg格式!");
return false;
}
fd.append("file",$(this).get(0).files[0]);
fd.append("pid",11);
$.ajax({
url:"/Frontajax/upload",
type:"POST",
processData: false,
contentType:false,
data: fd,
dataType: "json",
xhr: function() { // custom xhr
myXhr = $.ajaxSettings.xhr();
if(myXhr.upload){ // check if upload property exists
myXhr.upload.addEventListener('progress',function(evt){
//$( "#upload_tip").dialog("open");
var percentComplete = Math.round(evt.loaded*100 / evt.total);
console.log(percentComplete);
$( "#upload_tip").css("width",percentComplete*2);
$( "#upload_tip").html(percentComplete+'%');
}, false); // for handling the progress of the upload
}
return myXhr;
},
success:function(data){
var json=data;
if(json.status==1){
$("#fileurl").val(json.fileurl);
alert("上传成功!");
}
console.log(data.status);
}
});
});
});
</script>
<?php
public function upload(){
$pid=intval($_SESSION['pid']);
$projectid=intval($_SESSION['projectid']);
$ppinfo=pathinfo($_FILES['file']['name']);
$extname=strtolower($ppinfo['extension']);
$fileext=".txt";
switch ($extname) {
case 'zip':
$fileext=".zip";
break;
case 'rar':
$fileext=".rar";
break;
case 'jpg':
$fileext=".jpg";
break;
case 'pdf':
$fileext=".pdf";
break;
}
$basename=date("YmdHis").rand(10000,99999)."_".$pid.$fileext;
$midpath=ROOT_PATH."/upfiles/eppei";
if(!file_exists($midpath)){
mkdir($midpath,0774);
chmod($midpath,0774);
}
set_time_limit(300);
$status=0;
$fileurl="";
if(move_uploaded_file($_FILES["file"]["tmp_name"],$midpath."/".$basename)){
$status=1;
$fileurl="/upfiles/eppei/".$basename;
//附加字段
$att=new Attachinfo();
$att->where("projectid=".intval($projectid)." and pid=".intval($pid))->fetch();
$edudata=array();
$aid=intval($att->aid);
$att->clean(true);
if($aid>0){
$edudata['aid']=$aid;
$edudata['filename']="/upfiles/eppei/".$basename;
$att->where("projectid=".intval($projectid)." and pid=".intval($pid))->update($edudata);
}else{
$edudata['projectid']=intval($projectid);
$edudata['pid']=intval($pid);
$edudata['fromschool']='';
$edudata['techang']='';
$edudata['height']='';
$edudata['weight']='';
$edudata['direction']='';
$edudata['pic1']='';
$edudata['pic2']='';
$edudata['pic3']='';
$edudata['filename']="/upfiles/eppei/".$basename;
$att->setData($edudata)->save();
}
}
echo json_encode(array("status"=>$status,"fileurl"=>$fileurl));
exit;
}
?>
标签:intval,projectid,edudata,pid,upload,fileext,html,PHP,压缩包 来源: https://www.cnblogs.com/chouxiao/p/14984592.html