2011-05-03 96 views
0

我想上傳三張圖片中的圖片。我的文件夾結構如下: upload/large,upload/original,upload/thumb。 如何使用codeigniters的「上傳」庫將調整大小後的圖像存儲到這些文件夾中。在codeigniter中上傳圖片

回答

2

我與鈉同意,你需要接受更多的答案。

然而,對於這樣的問題: 它看起來對我像你其實只是上傳到原來的文件夾,然後用這個複製的圖像庫,所以,請嘗試以下操作:

$config['upload_path'] = './upload/original'; 
$config['allowed_types'] = 'gif|jpg|png'; 
$config['max_size'] = '100'; 
$config['max_width'] = '500'; 
$config['max_height'] = '300'; 
$this->load->library('upload', $config); 

$this->upload->do_upload() 
$upload_data = $this->upload->data(); 

$copies = array(
       array('dir' => 'upload/large', 'x' => 1000, 'y' => 600), //note: x&y could be replaced with a percentage or ratio etc. 
       array('dir' => 'upload/thumbnail', 'x' => 100, 'y' => 60) 
       ); 

foreach($copies as $copy) 
{ 
       $config['image_library'] = 'ImageMagick'; 
       $config['library_path'] = '/usr/bin/'; 
       $config['source_image'] = $upload_data['full_path']; 
       $config['new_image'] = $copy['dir'] . $upload_data['file_name']; 
       $config['maintain_ratio'] = TRUE; 
       $config['width'] = $copy['x']; 
       $config['height'] = $copy['y']; 
       $config['master_dim'] = 'width'; 
       $this->image_lib->initialize($config); 
       $this->image_lib->resize(); 
} 

希望這有助於!

+0

謝謝你這麼多..這對我有用。:) – 2011-05-03 12:18:37