php結合jquery異步上傳圖片(ajaxSubmit)

php結合jquery異步上傳圖片(ajaxSubmit)
php結合jquery異步上傳圖片(ajaxSubmit),如下爲提交頁面代碼:javascript

 

<!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下載php

https://github.com/malsup/formhtml

下載源碼:java

ajax_upfiles.rarjquery

轉載:http://skyhome.cn/jquery/246.htmlgit

相關文章
相關標籤/搜索