Board logo

標題: 有無師兄熟codeigniter ? 有關file upload [打印本頁]

作者: takayo72    時間: 2017-1-19 18:38     標題: 有無師兄熟codeigniter ? 有關file upload

提示: 作者被禁止或刪除 內容自動屏蔽
作者: 型氣小子    時間: 2017-1-19 21:50

本帖最後由 型氣小子 於 2017-1-19 21:52 編輯
  1. <form method="post" action="submit" enctype="multipart/form-data">
  2.     <input type="file" id="itemPictures" name="itemPictures[]" multiple>
  3. </form>
複製代碼
Controller:
  1. $files  = $_FILES;
  2. $file_count  = count($_FILES['itemPictures']['name']);
  3. for($i = 0; $i < $file_count; $i++) {
  4.         $_FILES['itemPictures']['name'] = $files['itemPictures']['name'][$i];
  5.         $_FILES['itemPictures']['type'] = $files['itemPictures']['type'][$i];
  6.         $_FILES['itemPictures']['tmp_name'] = $files['itemPictures']['tmp_name'][$i];
  7.         $_FILES['itemPictures']['error'] = $files['itemPictures']['error'][$i];
  8.         $_FILES['itemPictures']['size'] = $files['itemPictures']['size'][$i];

  9.         $config['upload_path'] = './upload';
  10.         $config['allowed_types'] = 'gif|jpg|png|jpeg';
  11.         $config['max_size'] = '5000';
  12.         $config['max_width'] = '5000';
  13.         $config['max_height'] = '5000';
  14.         $config['max_filename'] = 0;
  15.         $config['overwrite'] = false;
  16.         $config['remove_spaces'] = true;
  17.         $config['encrypt_name'] = false;
  18.         $config['file_name'] = 'file' . $i;
  19.         $this->upload->initialize($config);

  20.         if( ! $this->upload->do_upload('itemPictures')) {
  21.                 break; //skip and process next photo
  22.         } else {
  23.                 $upload = $this->upload->data();
  24.         }
  25. }
複製代碼

作者: 型氣小子    時間: 2017-1-19 21:53

hope this can help u
作者: takayo72    時間: 2017-1-20 06:12

提示: 作者被禁止或刪除 內容自動屏蔽
作者: takayo72    時間: 2017-1-20 13:19

提示: 作者被禁止或刪除 內容自動屏蔽
作者: 7h1r733n    時間: 2017-1-20 13:50

再問一下CI嘅嘢,


那個 $this->db->update_batch()  係點樣用㗎?唔太明佢個例子,第三個parameter ,wh ...
takayo72 發表於 2017-1-20 13:19

where係指第二個param入面邊個key做where key
作者: 7h1r733n    時間: 2017-1-20 13:57

  1. $data = array(
  2.    array(
  3.      'id'=>1,
  4.       'name' => 'Mixed paper' ,
  5.       'type' => 'paper' ,
  6.       'listorder' => '1'
  7.    ),
  8.    array(
  9.      'id'=>2,
  10.       'name' => 'mixed plastic' ,
  11.       'type' => 'plastic' ,
  12.       'listorder' => '2'
  13.    ),
  14.    array(
  15.      'id'=>3,
  16.       'name' => 'Aluminium' ,
  17.       'type' => 'aluminium' ,
  18.       'listorder' => '3'
  19.    ),
  20.    array(
  21.      'id'=>4,
  22.       'name' => 'Glass' ,
  23.       'type' => 'glass' ,
  24.       'listorder' => '4'
  25.    )

  26. );

  27. $this->db->update_batch($table,$data, 'id');
複製代碼
咁樣.. 明未?   個array只要放key field同你要update個field, 張form要有個hidden field射返個ID上黎...
作者: takayo72    時間: 2017-1-20 15:10

提示: 作者被禁止或刪除 內容自動屏蔽
作者: 型氣小子    時間: 2017-1-20 21:55

其實 CI 係幾好用, 多 d 討論大家都會有進步
作者: takayo72    時間: 2017-1-21 11:17

提示: 作者被禁止或刪除 內容自動屏蔽





歡迎光臨 電腦領域 HKEPC Hardware (https://www.hkepc.com/forum/) Powered by Discuz! 7.2