php结合jquery异步上传图片(ajaxSubmit)

技术分享
php结合jquery异步上传图片(ajaxSubmit),以下为提交页面代码:

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Ajax异步上传图片</title>
<script src="js/jquery-1.4.2.js" language="JavaScript" type="text/javascript"></script>
<script src="js/jquery.form.js" language="JavaScript" type="text/javascript"></script>
<script type="text/javascript">

function sky_upfiles(){
    var messtxt;
 $("#sky_upform").ajaxSubmit({
                                //dataType:‘script‘,
                                type:post,
                                url: "doupfiles.php",    
                                beforeSubmit: function(){
                                    $("#sky_txt").html("图片上传中...");
                                },
                                success: function(data){        
                                    if(data=="1"){
                                    messtxt = "上传成功!";
                                    }else if(data=="-1"){
                                    messtxt = "文件超过规定大小!";
                                    }else if(data=="-2"){
                                    messtxt = "文件类型不符!";
                                    }else if(data=="-3"){
                                    messtxt = "移动文件出错!";
                                    }else{
                                    messtxt = "未知错误!";
                                    }
                                    $("#sky_txt").html(messtxt);                
                                    //$("#sky_txt").append(data);
                                },
                                resetForm: false,
                                clearForm: false
                        });
                        //$("#upimgform").submit();
}

        </script>
</head>
<body>
<br />
<fieldset style="width:97%">
  <legend>上传文件</legend>
    <form enctype="multipart/form-data" id="sky_upform" name="sky_upform" action="" method="post">
    <table width="100%" border="0" align="center" cellpadding="3" cellspacing="0">
      <tr>
        <td width="100" align="right" class="f-12"></td>
        <td class="f-12" align="left">
        <input name="upfile" id="upfile" maxlength="20" size="40" type="file" value="" /><input name="upmit" type="button" id="upmit" value="上传" onclick="sky_upfiles()"/>
        <font color="red" id="sky_txt"></font></td>
      </tr>       
    </form>
        
</body>
</html>

jquery.form.js下载

https://github.com/malsup/form

下载源码:

技术分享 ajax_upfiles.rar

转载:http://skyhome.cn/jquery/246.html

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。