• 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="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;202px">
    <p id="upload_tip" style="margin:0xp;height:25px;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;
    }
    ?>
  • 相关阅读:
    几种参数传递问题(读c++ primer plus)
    开源技术知识
    指针、引用与句柄(综合别人博客,方便大家和自己学习)
    转OpenGLhttp://www.zwqxin.com/archives/opengl.html
    我电脑上安装的软件(XP系统,GIS专业)
    回忆照片
    Richfaces为何那么“慢”?
    Windows和Linux下Java程序开发入门
    MiniOA项目介绍及源代码下载(Java JSF B/S)
    年会抽奖程序代码讲解(c#版)
  • 原文地址:https://www.cnblogs.com/chouxiao/p/14984592.html
Copyright © 2020-2023  润新知