thinkphp批量上傳圖片
阿新 • • 發佈:2019-02-06
public function uploadimg(){ if (IS_POST) { $data = I('post.'); $data = I('post.'); $config = array( 'mimes' => array(), //允許上傳的檔案MiMe型別 'maxSize' => 0, //上傳的檔案大小限制 (0-不做限制) 'exts' => array('jpg','png','jpeg','gif'), //允許上傳的檔案字尾 'autoSub' => true, //自動子目錄儲存檔案 'subName' => array('date', 'Y-m-d'), //子目錄建立方式,[0]-函式名,[1]-引數,多個引數使用陣列 'rootPath' => './Uploads/Pic/', //儲存根路徑 'savePath' => '', //儲存路徑 ); $upload = new \Think\Upload($config); $info = $upload->upload(); foreach ($data as $key => $value) {} foreach ($info as $key => $v) {} for($i=0 ; $i < count($value) ; $i++){ $batch['pt_time'] = time(); $batch['pt_show'] = 0; $batch['pt_name'] = $data['pt_name'][$i]; $batch['pt_website'] = $data['pt_website'][$i]; $batch['pt_flag'] = $data['pt_flag'][$i]; $batch['pt_img'] = '/Uploads/Pic'.'/'.$info[$i]['savepath'].$info[$i]['savename']; M('Photos')->add($batch); } $this->redirect('edit',array('flag'=>7)); }else{ $this->display(); } }
<input name="pt_img[]" type="file" />