html上传压缩包后台PHP处理
2021/7/8 9:35:40
本文主要是介绍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; } ?>
这篇关于html上传压缩包后台PHP处理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-28怎么把PHP程序打包?-icode9专业技术文章分享
- 2024-09-28怎么用Phar打包PHP程序?-icode9专业技术文章分享
- 2024-09-13手动在github上下载的mfpt包,怎么放到thinkphp5.0框架并正常使用-icode9专业技术文章分享
- 2024-09-05python的<class 'bytearray'>相当于php的哪个数据类型-icode9专业技术文章分享
- 2024-09-05php 导出银行卡号避免科学技术法的方法-icode9专业技术文章分享
- 2024-08-30什么样的php代码质量差被称为垃圾代码-icode9专业技术文章分享
- 2024-08-30用 PHP 调用拼多多的接口以获取订单状态消息的步骤方法和代码示例-icode9专业技术文章分享
- 2024-08-27phpunit单元测试框架的入门和使用方法介绍-icode9专业技术文章分享
- 2024-08-24PHP 中date("w") 周一是多少-icode9专业技术文章分享
- 2024-08-14thinkphp8.0获取域名或主机名方法-icode9专业技术文章分享