当前位置:编程学习 > php >>

php无刷新文件上传代码

php无刷新文件上传代码

<?php
if (isset($_GET['action']) && $_GET['action']=='update')
{
    //update notice data
    //上传文件
    require_once("upload_class.php");
    $f = new Upload( $savepath, $fileFormat, $maxsize, $overwrite);
    if (!$f->run('img'))
    {//下面的img是Form中上传文件的input的名字
        echo $f->errmsg();  //这里只能传递最后一个出错的信息,详细的信息在$f->getInfo()中可以得到。
        print_r($f->returnArray);
    }
    echo "
    <script src="".__FILENAME__."/js/jquery.js" type="text/javascript"></script>
    <script>
    var ptext='';
    ptext="OK";
    //alert($('#img_view').html());
    parent.$('#img_view').html(ptext);
</script>";
}
?>

<!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" />
<link href="{{$tempurl}}/admin.css" rel="stylesheet" type="text/css" />
<link href="{{$baseurl}}/js/calendar/default/datePicker.css" rel="stylesheet" type="text/css" />
<script src="{{$baseurl}}/js/calendar/WdatePicker.js" type="text/javascript"></script>
<script src="{{$baseurl}}/js/jquery.js" type="text/javascript"></script>
<script src="{{$baseurl}}/js/Forms.js" type="text/javascript"></script>
<script src="{{$baseurl}}/js/FormValid.js" type="text/javascript"></script>
<script type="text/javascript">
      FormValid.succeed = function () {
      $.post("./article.php?action=update",$.getForms("update"),function (msg){
      alert(msg);
      if(msg=="更新公告成功")
      {
        location.href("./article.php");
      }
      //location.href("{{$baseurl}}/index.php");
  });
    return false; 
    }
function file_addupload(type)
{
  //负责增加图片输入框
  var ptext='';
  ptext=$("#"+type+"_more").html()+"<br /><input type='file' name='"+type+"[]' class='input' />";
  $("#"+type+"_more").html(ptext);
}
</script>
<title>发布文章--编辑页面</title>
</head>
<body >
<table width="99%" border="0" cellpadding="0" cellspacing="1" class="install">
  <tr>
    <td colspan="2" class="title">编辑文章内容</td>
  </tr>
  {{section name=article loop=$article}}
  <form action="./article.php?action=update" method="post" name="update" enctype="multipart/form-data" target="upload_iframe">
  <input type="hidden" name="article_id" value="{{$id}}">
  <tr>
    <td class="left">文章标题:</td>
    <td class="right"><input type="text" id="title" name="article_title" value="{{$article[article].title}}" class="input" size="35" valid="required" errmsg="文章标题不能为空" /></td>
  </tr>
  <tr>
    <td class="left">发布IP:</td>
    <td class="right"><input type="text" id="ip" value="{{$article[article].ip}}" name="ip" class="input" readonly /></td>
  </tr>
  <tr>
    <td class="left">作者:</td>
    <td class="right"><input type="text" id="author" name="article_validtime" value="{{$article[article].author}}"  valid="required" errmsg="请输入文章作者"  /></td>
  </tr>
  <tr>
    <td class="left">分类:</td>
    <td class="right"><select name='sort'>
{{html_options options=$sort_options selected=$article[article].sort }}
</select></td>
  </tr>
  <tr>
    <td class="left">来源:</td>
    <td class="right"><input type="text" id="comes" name="comes" value="{{$article[article].comes}}" class="input"/></td>
  </tr>
  <tr>
    <td class="left">是否置顶:</td>
    <td class="right">{{html_radios name='is_top' options=$is_top_radios checked=$article[article].is_top separator=' ' _note='是否置顶|radio|1=>是,0=>否' }}</td>
  </tr>
  <tr>
    <td class="left">内容:</td>
    <td class="right">{{$editor}}</td>
  </tr>
    <tr>
    <td class="left">图片上传:</td>
    <td class="right">
    <span id="img_view">
    <input type="file" name="img[]" class="input" />
      <a href="#" onclick="file_addupload('img')">++</a>
    <span id="img_more"></span>
    </span>
  </tr>
  <tr>
    <td class="left">文件上传:</td>
    <td class="right"><input type="file" name="file[]" class="input" />
      <a href="#" onclick="file_addupload('file')">++</a>
    <span id="file_more"></span>
</td>
  </tr>
  <tr>
    <td colspan="2" class="page" style="text-align:center;"><input type="submit" name="submit" class="button" value="保存" />    <input type="button" name="article_return" value="返回"  class="button" onclick="javascript:location.href('./article.php');" /></td>
  </tr>
  </form>
  {{/section}}
</table>
<iframe name="upload_iframe" style="width: 400px; height: 100px; display: none;">
</iframe>
</body>
</html>

补充:Php教程,Php常用代码 
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,