<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                >[danger] 先來看最基本的文件上傳表單,以及服務器接收到的數據結構 a.php ~~~ <?php if ($_POST) { echo '<pre>'; print_r($_POST); echo '</pre>'; echo '<hr>'; echo '<pre>'; print_r($_FILES); echo '</pre>'; exit; } ?> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <meta http-equiv="Content-Language" content="zh-cn"> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="keywords" content="keywords"> <meta name="description" content="description"> <link href="favicon.ico" rel="icon" type="image/x-icon"> <link href="" type="text/css" rel="stylesheet"> <script src=""></script> <title>Document</title> </head> <body> <form action="" method="post" enctype="multipart/form-data"> <input type="text" name="val" value="val"><br /> <input type="file" name="logo"><br /> <input type="file" name="pic"><br /> <input type="file" name="list[]"><br /> <input type="file" name="list[]"><br /> <input type="file" name="img-list[]"><br /> <input type="file" name="img-list[]"><br /><br /> <!-- 如果有name有值,則就會有一個$_POST[s] = 提交的值 --> <input type="submit" name="s" value="提交"><br /> <!-- 沒有提交效果 --> <input type="button" name="b" value="提交按鈕"><br /> <!-- 在form中有提交效果,type="submit" 也有提交效果,但是 type="button" 就沒有提交效果了 (注意所有的提交按鈕必須在form中才能提交除非用js控制) --> <button>按鈕</button> </form> </body> </html> ~~~ ![](https://box.kancloud.cn/992ce43b78c6c6e30255b27d67dc0714_314x280.jpg) 點擊 提交 : ~~~ Array ( [val] => val [s] => 提交 ) Array ( [logo] => Array ( [name] => QQ圖片20161106223133.jpg [type] => image/jpeg [tmp_name] => D:\wamp64\tmp\php92D0.tmp [error] => 0 [size] => 217991 ) [pic] => Array ( [name] => QQ圖片20161106223133.jpg [type] => image/jpeg [tmp_name] => D:\wamp64\tmp\php931F.tmp [error] => 0 [size] => 217991 ) [list] => Array ( [name] => Array ( [0] => QQ圖片20161106223133.jpg [1] => fdc20716fe1372b0859ec0019d7e6194.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg ) [tmp_name] => Array ( [0] => D:\wamp64\tmp\php932F.tmp [1] => D:\wamp64\tmp\php9350.tmp ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 217991 [1] => 6768 ) ) [img-list] => Array ( [name] => Array ( [0] => QQ圖片20161106223133.jpg [1] => bg-01.jpg ) [type] => Array ( [0] => image/jpeg [1] => image/jpeg ) [tmp_name] => Array ( [0] => D:\wamp64\tmp\php9351.tmp [1] => D:\wamp64\tmp\php9361.tmp ) [error] => Array ( [0] => 0 [1] => 0 ) [size] => Array ( [0] => 217991 [1] => 471588 ) ) ) ~~~ **上面就是所有最基本的表單上傳,最基本的上傳數據結構了。** 文件上傳根據類型,可分為兩種: - **單文件上傳** - 單一字段 - **多文件上傳** - 多字段的形式多文件 - 單一字段數組(img[])的形式多文件上傳**(這種最復雜,注意這種形式的數據結構)** - 組合多文件(上面幾種情況的組合) 參考: [修復Request->file()判斷臨時文件不嚴謹導致多文件上傳失敗的情況](https://github.com/top-think/framework/pull/348) [文件上傳那些事兒](https://mp.weixin.qq.com/s/ni_5rZDCOypxtHrVXq1Aww) ### 擴展 ~~~html <input type="file" multiple name="pic[]"> ~~~ `multiple`是HTML5新增的屬性,這個屬性可以使上傳表單上傳時選擇多個文件,點擊“選擇文件”,在彈出系統選擇文件窗口中按住`Ctrl`鍵可以連續選擇多個文件,**但是此屬性必須配合pic[]數組字段的形式才有作用(注意有些上傳插件比如uploadify,這些可以選擇多文件上傳,此時可能也有這個問題,注意檢查上傳字段名的設置)**,否則即使選擇多個文件,提交到服務器也只有最后一個選擇的文件。(所以這個屬性可以用來避免以前上傳多文件需要多表單,僅一個表單就搞定了) * * * * * ### 其他 對于前端來說,圖片上傳有以下知識點: - 普通上傳 - ajax無刷新文件上傳 - 大文件分塊上傳 - MD5提前校驗去重,存在不上傳(傳到服務端再校驗用處不大,只是節省空間,但是并沒有節省不必要上傳的流量) - 圖像壓縮上傳 - 圖像裁剪(放大,縮小,旋轉等手勢操作) 這些操作以前只有flash才能全部做到,現在html5的新API也能夠做到了,不過大部分接口對瀏覽器的版本要求比較高。 服務端收到文件的方式無非兩種: 1. 普通的$\_FIELS 2. base64編碼的字符圖片$\_POST(非常規Coentent-Type時用`file_get_contents('php://input', 'r')`) **參考:** [php://input - 簡單--生活 - 博客園](http://www.cnblogs.com/xiangxiaodong/archive/2012/11/07/2758685.html) [PHP: php:// - Manual](http://php.net/manual/zh/wrappers.php.php) * * * * * [Http 歷險記(上)](https://mp.weixin.qq.com/s?__biz=MzAxOTc0NzExNg==&mid=2665513069&idx=1&sn=548c497c46c7c076145064a120c7c101&scene=21#wechat_redirect) [Http歷險記(下)-- Struts的秘密](https://mp.weixin.qq.com/s?__biz=MzAxOTc0NzExNg==&mid=2665513080&idx=1&sn=d24a4cdfc71412c581393d584fd91326&scene=21#wechat_redirect) * * * * * last update:2017-8-17 09:45:38
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看