简体   繁体   English

CodeIgniter多个图像上传并调整大小

[英]CodeIgniter multiple image upload and resize

As i am beginner in PHP so i am facing difficulty even after the help of tutorials. 因为我是PHP的初学者,所以即使在教程的帮助下,我也面临着困难。 My code upload the multiple pictures but it re-size only 1st Picture and rest of the pictures remain same as they are uploaded. 我的代码上传了多张图片,但只调整了第一张图片的大小,其余图片与上传的图片相同。 I have tried unset and clear() but problem is same. 我尝试过unset和clear(),但是问题是相同的。 I will really appreciate if some one will help me to resolve this problem. 如果有人能帮助我解决这个问题,我将不胜感激。

function do_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['upload_path'] = './uploads/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size']    = '2000';
            $config['max_width']   = '1024';
            $config['max_height']  = '768';

            $this->load->library('upload', $config);

            if ( ! $this->upload->do_upload())
            {
                $error = array('error' => $this->upload->display_errors());    
                $this->load->view('upload_form', $error);
            }
            else
            {
                $data = array('upload_data' => $this->upload->data());    
                $path=$data['upload_data']['full_path'];
                $q['name']=$data['upload_data']['file_name'];

                 $configi['image_library'] = 'gd2';
                 $configi['source_image']   = $path;
                 $configi['maintain_ratio'] = TRUE;
                 $configi['width']  = 75;
                 $configi['height'] = 50;

                $this->load->library('image_lib', $configi);    
                $this->image_lib->resize();

                $this -> load -> view('upload_success', $q);
                unset($configi);
                $this->load->library('image_lib');
                $this->image_lib->clear(); }}}

on last 6th line i have used 在我使用的最后第六行

$this->load->library('image_lib', $configi);

But when we load a library in loop with $configi it make instant when loop execute 1st time. 但是,当我们使用$ configi循环加载一个库时,它会在第一次执行循环时立即生效。 to use new values on every increment of loop we should perform them separately like: 在循环的每个增量上使用新值,我们应该分别执行它们,例如:

$this->load->library('image_lib');
$this->image_lib->initialize($configi);

and using this way $configi take new values at every increment in loop. 并使用这种方式$ configi在循环中的每个增量处获取新值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM