1

何とか複数の画像をアップロードしてサイズを変更できましたが、すべて問題ありませんでした。
次に、アップロードする画像が選択されていない場合にエラーを表示したかったのです。
エラーをロードするためにif文を入れましたが、それが大混乱を引き起こしています。

画像を選択してアップロードするたびに、サイズを変更せずに最後の画像が複製されます。
繰り返しますが、if else を削除すると、まったく問題ありません。

助けてくれてありがとう。

function do_upload(){


    $path = array();
    $count = count($_FILES['userfile']['size']);

    foreach($_FILES as $key=>$value){
        for($n=0; $n<=$count-1; $n++) {
            $_FILES['userfile']['name']=$value['name'][$n];
            $_FILES['userfile']['type']    = $value['type'][$n];
            $_FILES['userfile']['tmp_name'] = $value['tmp_name'][$n];
            $_FILES['userfile']['error']       = $value['error'][$n];
            $_FILES['userfile']['size']    = $value['size'][$n];   

                $config['upload_path'] = './images';
                $config['allowed_types'] = 'gif|jpg|png|jpeg';

            $this->load->library('upload', $config);
            $this->upload->do_upload();
            $data = $this->upload->data();
            $path[] = $data['full_path'];
        }   



        if(!$this->upload->do_upload()){
            $error = array('error' => $this->upload->display_errors());
            $this->load->view('view_dashboard_error_car', $error);
        }
        else{
            $this->load->library('image_lib');   

            foreach($path as $p=>$ath){
                $config1 = array(
                'source_image'      => $ath,
                'new_image'         => './images',
                'maintain_ration'   => true,
                'overwrite'         => true, 
                'width'             => 600,
                'height'            => 400
                );

                $this->image_lib->initialize($config1);
                $this->image_lib->resize();
                $this->image_lib->clear();
            }       



            $this->load->view('view_dashboard_success_car');

        }





    }   




}
4

1 に答える 1