码迷,mamicode.com
首页 > Web开发 > 详细

thinkphp 关于iframe一次提交完成所有操作

时间:2014-07-16 19:17:35      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:style   color   文件   os   width   art   

  一、上传操作html界面,upload.html  

    <import type=‘css‘ file="admin.css.common" />
    <import type=‘css‘ file="admin.css.main" />
    <form action="{:U(‘Public/upload_post‘)}" style="height:40px;" enctype="multipart/form-data" method="post" >
    <input type="file" name="photo" class="input-text lh30" size="10" />
    </form>

  二、页面引用upload页面

     <input type="hidden" name="picurl" id="picurl" value="" />

    <iframe width="100%" id="uploadframe" name="uploadframe" frameborder="0" height="40" src="{:U(‘Public/upload‘)}"></iframe>

  三、点击提交   

    <input type="submit" onclick="return jc();" name="button" class="btn btn82 btn_save2" value="保存">
    <input type="resit" name="button" class="btn btn82 btn_res" value="重置">

  四、js提交操作,实现upload页面上传提交操作  

    function jc(){
          if($(window.frames["uploadframe"].document).contents().find("input").val()){
          $(window.frames["uploadframe"].document).contents().find("form").submit();
            return false;
              }
           }

  五、上传控制器处理。当上传成功后,js使父框架原表单提交。

      public function upload_post(){
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728 ;// 设置附件上传大小
        $upload->exts = array(‘jpg‘, ‘gif‘, ‘png‘, ‘jpeg‘);// 设置附件上传类型
        $upload->rootPath = ‘./Uploads/‘; // 设置附件上传根目录
        $upload->savePath = ‘‘; // 设置附件上传(子)目录
            // 上传文件
        $info = $upload->upload();
        if(!$info) {// 上传错误提示错误信息
        $this->error($upload->getError());
          }else{// 上传成功
        echo ‘<script>parent.document.getElementById("picurl").value="‘. $info["photo"][‘savepath‘].$info["photo"][‘savename‘].‘";
          parent.document.getElementById("myFrom").submit(); </script>‘;
        // $this->success(‘上传成功!‘);
            }
        }

  

thinkphp 关于iframe一次提交完成所有操作,布布扣,bubuko.com

thinkphp 关于iframe一次提交完成所有操作

标签:style   color   文件   os   width   art   

原文地址:http://www.cnblogs.com/xiamibk/p/3844749.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!