2個Codeigniter檔案批量上傳控制器寫法例子,codeigniter寫法_PHP教程

來源:互聯網
上載者:User

2個Codeigniter檔案批量上傳控制器寫法例子,codeigniter寫法


例子一:

/** * 多檔案上傳 *  * @author Dream  */public function multiple_uploads() {  //載入所需類庫  $this->load->library('upload');    //配置上傳參數  $upload_config = array(      'upload_path'  => '',      'allowed_types' => 'jpg|png|gif',      'max_size'   => '500',      'max_width'   => '1024',      'max_height'  => '768',  );  $this->upload->initialize($upload_config);      //迴圈處理上傳檔案  foreach ($_FILES as $key => $value) {    if (!empty($key['name'])) {      if ($this->upload->do_upload($key)) {        //上傳成功        print_r($this->upload->data());      } else {        //上傳失敗        echo $this->upload->display_errors();      }    }  }}

例子二:

function upload() {    $config['upload_path'] = './uploads/';     /*這裡的uploads是相對於index.php的,也就是入口檔案,這個千萬不要弄錯哦!    否則就會報錯"The upload path does not appear to be valid.";     */    $config['allowed_types'] = 'gif|jpg|png';    /*我試著去上傳其它類型的檔案,這裡一定要注意順序!     A problem was encountered while attempting to move the uploaded file to the final destination.    這個錯誤一般是上傳檔案的檔案名稱不能是中文名,這個很鬱悶!還未解決,大家可以用其它方法,重新改一下檔案名稱就可以解決了!     $config['allowed_types'] = 'zip|gz|png|gif|jpg';(正確)    $config['allowed_types'] = 'png|gif|jpg|zip|gz';(錯誤)    */    $config['max_size'] = '1024';    $config['max_width'] = '1024';    $config['max_height'] = '768';    $config['file_name'] = time(); //檔案名稱不使用原始名    $this->load->library('upload', $config);    if(!$this->upload->do_upload()) {        echo $this->upload->display_errors();    }else{       $data['upload_data']=$this->upload->data(); //檔案的一些資訊       $img=$data['upload_data']['file_name']; //取得檔案名稱       echo $img."
"; foreach($data['upload_data'] as $item => $value){ echo $item.":".$value."
"; } }}

對於CodeIgniter訪問的問題?

本地地址/CodeIgniter/index.php?/
本地地址/CodeIgniter/index.php?/welcome
本地地址/CodeIgniter/index.php?/welcome/
本地地址/CodeIgniter/index.php?/welcome/index
本地地址/CodeIgniter/index.php?/welcome/index/
試試加上?
 

codeigniter檔案上傳後得到的絕對路徑

因為使用上傳類你可以設定上傳目錄
所以這個時候其實你是知道直接目錄的,那對應的存入資料庫只要隱藏檔名稱就可以了

如果目錄是變動的(例如按年月日變動),因為也是你事Crowdsourced Security Testing道的,也可以組織好對應的相對路徑儲存到資料庫

如果寫在對應的設定檔中,即可當變數使用了
 

http://www.bkjia.com/PHPjc/848799.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/848799.htmlTechArticle2個Codeigniter檔案批量上傳控制器寫法例子,codeigniter寫法 例子一: /** * 多檔案上傳 * * @author Dream dream@shanjing-inc.com */public function multiple_up...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.