在codeigniter中调整多个图像的大小

时间:2014-08-06 22:32:39

标签: image codeigniter class

上传工作正常。尺寸调整仅适用于第一张图像和问题。我做了一个循环只有在他完成所有上传后才能运行。有谁知道怎么解决吗?谢谢!

     function do_upload() {
        $this -> load -> library('upload');
        if (isset($_FILES)) {

            $files = $_FILES;
            $cpt = @count($_FILES['userfile']['name']);
            //echo $cpt;
            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];

                $nome = $files['userfile']['name'][$i];
                $nomeTratado = strtr($nome, "áàãâéêíóôõúüçÁÀÃÂÉÊÍÓÔÕÚÜÇ ", "aaaaeeiooouucAAAAEEIOOOUUC_");
                $nome = $_FILES['userfile']['name'] = rand() . rand() . $nomeTratado;

                $nomeEdita[] = $nome;

                $id = $this -> Model_imovel -> pegaIdMaximo();
                $data = array('imovel_idimovel' => $id[0] -> idimovel, 'nome' => $nome, 'url' => base_url("assets/images/imoveis/mini") . "/" . $nome);

                //var_dump($id[0]->idimovel);
                $this -> upload -> initialize($this -> set_upload_options());
                $this -> upload -> do_upload();
                //$this->set_image_options();
                $this -> Model_upload -> insertFotos($data);

            }

        }
//here is calling the image resize function
        for ($i = 0; $i < $cpt; $i++) {
                $this-> editarFotoMini($nomeEdita[$i]);

            }
        $this -> uploadForm();

    }
//here the image resize function 
    private function editarFotoMini($nome) {

        $config['image_library'] = 'gd2';
        $config['source_image'] = './assets/images/imoveis/' . $nome;
        $config['maintain_ratio'] = TRUE;
        $config['width'] = 600;
        $config['height'] = 600;
        $config['new_image'] = './assets/images/imoveis/mini/' . $nome;

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

    }

1 个答案:

答案 0 :(得分:0)

替换

$_FILES['userfile'] 

$_FILES['userfile']['name'] 
在你的for循环中

并使用

$cpt = @count($_FILES['userfile']);

计算图片上传数组。