0
我已經生成了一個代碼,它將在codeigniter中上傳多個圖像,但是我無法使用codeigniter圖像庫生成大尺寸的上傳圖像到其他目錄。上傳多個圖像並生成大尺寸
使用下面的代碼,即使用戶上傳了多個圖像,它也只會生成一個圖像。
function insert_prod(){
$foldername = $_POST['folder'];
$path = './uploads/products/'.$foldername;
mkdir($path, 0777, true);
mkdir($path.'/zoomimages', 0777, true);
$config = array();
$config['upload_path'] = $path;
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '0';
$config['overwrite'] = FALSE;
$this->load->library('upload');
$files = $_FILES;
$cpt = count($_FILES['userfile']['name']);
for($i=0; $i<$cpt; $i++){
$_FILES['userfile']['name']= $files['userfile']['name'][$i];
$_FILES['userfile']['type']= $files['userfile']['type'][$i];
$_FILES['userfile']['tmp_name']= $files['userfile']['tmp_name'][$i];
$_FILES['userfile']['error']= $files['userfile']['error'][$i];
$_FILES['userfile']['size']= $files['userfile']['size'][$i];
$config['file_name'] = 'img_'.$i;
$this->upload->initialize($config);
$this->upload->do_upload();
$upload_data = array('upload_data' => $this->upload->data());
$full_path = $upload_data['upload_data']['full_path'];
$u_data = $upload_data['upload_data'];
// var_dump($this->upload->data());
// var_dump($upload_data);
echo $cpt;
$config1['image_library'] = 'gd2';
$config1['source_image'] = $full_path;
$config1['new_image'] =$path.'/zoomimages';
$config1['create_thumb'] = FALSE;
$config1['maintain_ratio'] = TRUE;
$config1['width'] = 300;
$config1['height'] = 300;
$this->load->library('image_lib', $config1);
$this->image_lib->resize();
$this->image_lib->clear();
}
}
對於每個上傳指定輸入名稱'$ this-> upload-> do_upload('NAME');' – Minhaz
檢查此http://stackoverflow.com/questions/11 524356/multiple-files-upload-array-with-codeigniter-2-0 – Minhaz
我正在使用該代碼。我可以上傳多張圖片,但我想爲圖片生成一個大尺寸,並將其放在其他目錄中。 –