Welcome Guest, Not a member yet? Register   Sign In
Validation and Upload simultaneously
#1

[eluser]haily_php[/eluser]
I have product's form which consists of many various fields as: product's name, price, image,... I have checked one-by-one condition.

* Upload for image:
Code:
if(isset($_FILES['product_img']) && !empty($_FILES['product_img']['name'])){
                        if(!$this->upload->do_upload("product_img")){
                            $data['error'] =$this->upload->display_errors();
                            $this->my_layout->view("add_v",$data);
                            
                        }else{
                            $data=$this->upload->data();
                                $config['image_library'] = 'gd2';
                                $config['source_image']    = './uploads/product/'.$data['file_name'];
                                $config['create_thumb'] = TRUE;
                                $config['maintain_ratio'] = TRUE;
                                $config['width']     = 200;
                                $config['height']    = 95;
                            
                            $this->load->library('image_lib', $config);
                            $this->image_lib->resize();    
                            $image= $data['file_name'];////     When anyone does not click to upload, program will save image's field to be $data['file_name']
                            }
            }else{
                    $image=""; //     When anyone does not click to upload, program will save image's field to be ""
            }


* Vaildation for other field:

Code:
if($this->form_validation->run()==FALSE){
            $this->my_layout->view("add_v",$data);    
            }

I went them in "if... else loop" and all of them that are ok. But, when I want to save them, I have problem in Image's field, program is not understand. So what will I want to do to save all of them successfully. I have tried many other ways but it has not run exact.

All my codes:

Code:
if($this->form_validation->run()==FALSE){
            $this->my_layout->view("add_v",$data);    
            }else if(isset($_FILES['product_img']) && !empty($_FILES['product_img']['name'])){
                        if(!$this->upload->do_upload("product_img")){
                            $data['error'] =$this->upload->display_errors();
                            $this->my_layout->view("add_v",$data);
                            
                        }else{
                            $data=$this->upload->data();
                                $config['image_library'] = 'gd2';
                                $config['source_image']    = './uploads/product/'.$data['file_name'];
                                $config['create_thumb'] = TRUE;
                                $config['maintain_ratio'] = TRUE;
                                $config['width']     = 200;
                                $config['height']    = 95;
                            
                            $this->load->library('image_lib', $config);
                            $this->image_lib->resize();    
                            $image= $data['file_name'];
                            }
            }else if(!isset($_FILES['product_img'])){
                        $image= "";
            }else if(?????){ // I don't know any right condition
                $data1=array(
                    "name"     =>    $this->input->post("product_name"),
                    "image"    =>    $image, // true or false
                    "content"        =>    $this->input->post("product_content"),
                    "price"            =>    $this->input->post("product_old_price"),,
                    "visible"        =>    $this->input->post("visible"),
                    );
                    
        
            
            echo "<pre>";
            print_r($data1);
            echo"</pre>";
        
    }


Messages In This Thread
Validation and Upload simultaneously - by El Forum - 05-14-2011, 11:13 PM
Validation and Upload simultaneously - by El Forum - 05-14-2011, 11:33 PM
Validation and Upload simultaneously - by El Forum - 05-14-2011, 11:39 PM



Theme © iAndrew 2016 - Forum software by © MyBB