Ich versuche Bilder hochzuladen und sie in verschiedenen Dimensionen innerhalb der gleichen Funktion neu zu sortieren. aber was passiert, ist, dass nur eine Größe funktioniert und die anderen nicht. Mein Code ist:Mehrere Bildgrößen auf einmal in Codeigniter, funktioniert nicht
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>';
}
}
Was mache ich hier falsch?
danke, das hat tatsächlich funktioniert –