thinkphp 關於iframe一次提交完成所有操作

來源:互聯網
上載者:User

標籤: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(‘上傳成功!‘);
            }
        }

  

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.