我想同樣的功能中上傳不同尺寸的圖像,並重新大小他們。但是會發生什麼情況是,只有一個重新調整大小,而另一個則不行。我的代碼是:多圖像大小調整在笨一次,將無法正常工作
function do_upload()
{
$this_user = $this->auth->info;if(!is_dir('./uploads/'.$this_user->username)){
mkdir('./uploads/'.$this_user->username);
mkdir('./uploads/'.$this_user->username.'/photos');
mkdir('./uploads/'.$this_user->username.'/photos/master');
mkdir('./uploads/'.$this_user->username.'/photos/small');
mkdir('./uploads/'.$this_user->username.'/photos/medium');
mkdir('./uploads/'.$this_user->username.'/photos/large');
mkdir('./uploads/'.$this_user->username.'/photos/xlarge');
}
$config['upload_path'] = './uploads/'.$this_user->username.'/photos/master/';
$config['allowed_types'] = 'gif|jpg';
$title = $this->input->post('title');
$this->load->library('upload', $config);
if (! $this->upload->do_upload())
{
echo '<div id="status">error</div>';
echo '<div id="message">'. $this->upload->display_errors() .'</div>';
}
else
{
$data = array('upload_data' => $this->upload->data());
//resizing begins
$image_width = $data['upload_data']['image_width'];
$image_height = $data['upload_data']['image_height'];
$full_path = $data['upload_data']['full_path'];
//checking for width
if($image_width>5000){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 5000;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/xlarge';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
if($image_width>=4500){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 4500;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/large';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
if($image_width>=2000){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 2000;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/medium';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
if($image_width>=800){
$config['image_library'] = 'gd2';
$config['source_image'] = $full_path;
//$config['create_thumb'] = TRUE;
$config['maintain_ratio'] = TRUE;
$config['width'] = 800;
//$config['height'] = 50;
$config['new_image'] = './uploads/'.$this_user->username.'/photos/small';
$this->load->library('image_lib', $config);
$this->image_lib->resize();
}
//resizing ends
echo '<div id="status">success</div>';
//then output your message (optional)
echo '<div id="message">'. $data['upload_data']['file_name'].$this->input->post('type').' Successfully uploaded.</div>';
//pass the data to js
echo '<div id="upload_data">'. json_encode($data) . '</div>';
}
}
我在做什麼錯在這裏?
感謝,這實際工作 – 2012-03-29 05:32:04