<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                ##上傳文件 ThinkPHP5.0對文件上傳的支持更加簡單。 假設表單代碼如下: ~~~ <form action="/index/index/upload" enctype="multipart/form-data" method="post"> <input type="file" name="image" /> <br> <input type="submit" value="上傳" /> </form> ~~~ 然后在控制器中添加如下的代碼: ~~~ public function upload(){ // 獲取表單上傳文件 例如上傳了001.jpg $file = request()->file('image'); // 移動到框架應用根目錄/public/uploads/ 目錄下 if($file){ $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads'); if($info){ // 成功上傳后 獲取上傳信息 // 輸出 jpg echo $info->getExtension(); // 輸出 20160820/42a79759f284b767dfcb2a0197904287.jpg echo $info->getSaveName(); // 輸出 42a79759f284b767dfcb2a0197904287.jpg echo $info->getFilename(); }else{ // 上傳失敗獲取錯誤信息 echo $file->getError(); } } } ~~~ move方法成功的話返回的是一個\\think\\File對象,你可以對上傳后的文件進行后續操作 ## \## 多文件上傳 如果你使用的是多文件上傳表單,例如: ~~~ <form class="form form-horizontal" method="post" action="{:url('admin/article/addArticle')}" enctype="multipart/form-data"> <div class="row cl"> <label class="form-label col-xs-4 col-sm-2">圖集:</label> <div class="formControls col-xs-8 col-sm-9"> <input id="file-0" type="file" multiple class="file" name="path[]" > </div> </div> <div class="row cl"> <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2"> <input class="btn btn-primary radius" type="submit" value="&nbsp;&nbsp;提交&nbsp;&nbsp;"> </div> </div> </form> ~~~ 控制器代碼可以改成: ~~~ public function addArticle() { //判斷提交的方式 if(\request()->isPost()){ //多圖上傳 $arryFile =\request()->file("path"); $arrImg=[]; foreach ($arryFile as $File){ $pathImg=""; //移動文件到框架應用更目錄的public/uploads/ $info = $File->move(ROOT_PATH . 'public' . DS . 'upload' . DS . 'article' . DS . date('Y') . DS . date('m-d'),md5(microtime(true))); if ($info) { $pathImg = "/public/upload/article/" . date('Y') . '/' . date('m-d') . '/' . $info->getFilename(); } else { //錯誤提示用戶 return $this->error($File->getError()); } // $result["img_url"] $arrImg[]= $pathImg; } $insert_data["img_url"]=implode(",",$arrImg); Db::name("articles")->insert($insert_data); } return $this->fetch("article-add"); } ~~~ 上傳驗證 支持對上傳文件的驗證,包括文件大小、文件類型和后綴: ~~~ public function upload(){ // 獲取表單上傳文件 例如上傳了001.jpg $file = request()->file('image'); // 移動到框架應用根目錄/public/uploads/ 目錄下 $info = $file->validate(['size'=>15678,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads'); if($info){ // 成功上傳后 獲取上傳信息 // 輸出 jpg echo $info->getExtension(); // 輸出 20160820/42a79759f284b767dfcb2a0197904287.jpg echo $info->getSaveName(); // 輸出 42a79759f284b767dfcb2a0197904287.jpg echo $info->getFilename(); }else{ // 上傳失敗獲取錯誤信息 echo $file->getError(); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看