Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter中的多个图像同时调整大小,赢得';行不通_Php_Codeigniter_Image Manipulation - Fatal编程技术网

Php Codeigniter中的多个图像同时调整大小,赢得';行不通

Php Codeigniter中的多个图像同时调整大小,赢得';行不通,php,codeigniter,image-manipulation,Php,Codeigniter,Image Manipulation,我正在尝试上传图像,并在同一功能中以不同的维度重新调整它们的大小。但实际情况是,只有一个重新调整了大小,而其他的没有。我的代码是: function do_upload() { $this_user = $this->auth->info;if(!is_dir('./uploads/'.$this_user->username)){ mkdir('./uploads/'.$this_user->username); mkdi

我正在尝试上传图像,并在同一功能中以不同的维度重新调整它们的大小。但实际情况是,只有一个重新调整了大小,而其他的没有。我的代码是:

    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>';

    }
}
函数do_upload()
{
$this_user=$this->auth->info;如果(!is_dir('./uploads/'.$this_user->username)){
mkdir('./上传/'.$this\u用户->用户名);
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);
如果(!$this->upload->do_upload())
{
回声“错误”;
回显“”。$this->upload->display_errors();
}
其他的
{
$data=array('upload_data'=>$this->upload->data());
//开始调整大小
$image_width=$data['upload_data']['image_width'];
$image_height=$data['upload_data']['image_height'];
$full_path=$data['upload_data']['full_path'];
//检查宽度
如果($image_width>5000){
$config['image_library']='gd2';
$config['source\u image']=$full\u 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();
}
如果($image\u width>=4500){
$config['image_library']='gd2';
$config['source\u image']=$full\u 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();
}
如果($image\u width>=2000){
$config['image_library']='gd2';
$config['source\u image']=$full\u 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();
}
如果($image\u width>=800){
$config['image_library']='gd2';
$config['source\u image']=$full\u 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();
}
//调整末端尺寸
呼应"成功",;
//然后输出消息(可选)
echo'.$data['upload_data']['file_name'.$this->input->post('type').“已成功上载”;
//将数据传递给js
回显“”。json_编码($data)。“”;
}
}

我做错了什么?

您需要确保调用
$this->image_lib->clear()重置图像处理类的初始化。请看:

这实际上对我很有效。我所做的是多次加载库。我应该加载库一次,并为每次重新调整大小初始化配置。这是为我工作的代码

    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
            $this->load->library('image_lib');
            if($image_width>5000){
                $config['source_image'] = $full_path;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 5000;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/xlarge';
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
                $this->image_lib->clear();
                $aa = 'xlarge ';
            }
            if($image_width>=4500){
                $config['source_image'] = $full_path;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 4500;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/large';
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
                $this->image_lib->clear();
                $aa .= 'large';
            }
            if($image_width>=2000){
                $config['source_image'] = $full_path;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 2000;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/medium';
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
                $this->image_lib->clear();
                $aa .= 'medium';
            }
            if($image_width>=800){
                $config['source_image'] = $full_path;
                $config['maintain_ratio'] = TRUE;
                $config['width'] = 800;
                $config['new_image'] = './uploads/'.$this_user->username.'/photos/small';
                $this->image_lib->initialize($config);
                $this->image_lib->resize();
                $this->image_lib->clear();
                $aa .= 'small';
            }
        //resizing ends
        echo '<div id="status">success</div>';
        //then output your message (optional)
        echo '<div id="message">'. $data['upload_data']['file_name'].$aa.' Successfully uploaded.</div>';
        //pass the data to js
        echo '<div id="upload_data">'. json_encode($data) . '</div>';

    }
}
函数do_upload()
{
$this_user=$this->auth->info;
如果(!is_dir('./上传/'.$this_user->username)){
mkdir('./上传/'.$this\u用户->用户名);
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);
如果(!$this->upload->do_upload())
{
回声“错误”;
回显“”。$this->upload->display_errors();
}
其他的
{
$data=array('upload_data'=>$this->upload->data());
//开始调整大小
$image_width=$data['upload_data']['image_width'];
$image_height=$data['upload_data']['image_height'];
$full_path=$data['upload_data']['full_path'];
//检查宽度
$this->load->lib('image_lib');
如果($image_width>5000){
$config['source\u image']=$full\u path;
$config['maintain_ratio']=TRUE;
$config['width']=5000;
$config['new_image']='./uploads/'.$this_user->username./photos/xlarge';
$this->image\u lib->initialize($config);
$this->image_lib->resize();
$this->image_lib->clear();