-
-
class Upload extends Controller {
- function go() {
- if(isset($ _POST[ 'go'])) {
- // 初始化
- $config['upload_path'] = 'album/source';
- $config['allowed_types'] = 'gif|jpg|png|bmp|jpeg';
- $config['encrypt_name'] = TRUE;
- $config['remove_spaces'] = TRUE;
- $config['max_size'] = '0';
- $config['max_width'] = '0';
- $config['max_height'] = '0';
$this->load->library('upload', $config);
//170*170圖片
- $configThumb = array();
- $configThumb['image_library'] = 'gd2';
- $configThumb['source_image'] = '';
- $configThumb ['create_thumb'] = TRUE;
- $configThumb['maintain_dratb['maintain_真的; //保留圖片比例
- $configThumb['new_image'] = 'album/thumb';
- $configThumb['width'] = 170;
- $configThumb['height'] = 170;
- //600*600圖片
- $configLarge = array();
- $configLarge['image_library'] = 'gd2';
- $configLarge['source_image'] = '';
- $ configLarge['create_thumb'] = TRUE;
- $configLarge['maintain_ratio'] = TRUE; // 保持圖片比例
- $configLarge['new_image'] = 'album/large';
- $configLarge['width'] = 600;
- $configLarge['height'] = 600;
- $configLarge['height'] = 600;
- /p>
$this->load->library('image_lib');
for($ i = 1; $i $upload = $this->upload->do_upload('image'.$i);
- if($upload === FALSE) continue;
- $data = $this->upload->data();//返回上傳檔案的記憶體的所有相關資訊
- $uid = $this ->session->userdata('uid');
- $uploadedFiles[$i] = $data;
if($data['is_image'] == 1) {
- // 初始化170*170
- $configThumb['source_image'] = $data['full_path']; //檔案路徑帶檔名
- $this->image_lib->initialize($configThumb);
- $this->image_lib->resize();
- //初始化600*600
- $ configLarge['source_image'] = $data['full_path']; //檔案路徑帶檔名
- $this->image_lib->initialize($configLarge);
- $this->image_lib->resize();
- }
//插入圖片資訊到相簿表,插入的檔案名稱為source目錄檔案名稱
- $picture = array(
- 'filename' => $data['file_name'],
- 'albumID' = > $this->uri->segment(4,0),
- 'uid' => $this->session->userdata('uid'),
- 'dateline' => 時間(),
- '描述' => '',
- '點擊' => 0
- );
$this->load->model('album_model');
- $this->album_model->AddPic($picture);
- $picture = array();
- }
- }
- /* 轉出*/
- $albumID = $this- >uri->segment(4);
- $backurl = site_url() . 'photo/editpic/album/' .$albumID;
- $this->session->set_flashdata('msg','圖片上傳成功.');
- redirect($backurl,'刷新') ;
- }
}
複製程式碼
複製程式碼type="submit" name="go" value="上傳照片" class="button" />
注意事項:
1,要一次上傳幾個文件,修改表單和控制器中循環部分的參數就好。
2,album\source 是上傳後原圖目錄 large和thumb分別是兩次執行$this->image_lib->resize();後存放縮圖的目錄。
3,縮圖檔名,如需和album\source目錄一致,請新增參數 $config['thumb_marker'] = '';。
4,$picture 這部分數組是保存到資料庫的東西,無需理會。
|