Welcome Guest, Not a member yet? Register   Sign In
Upload 2 photos
#1

[eluser]Fr334Ever[/eluser]
Hi there , I have a small problem with photo uploadin on my site for product.

I have this controller for products admin function add

Code:
function add() {

                //pictures
                $config['upload_path'] = 'upload/';
                $config['allowed_types'] = 'gif|jpg|png|jpeg';
                $config['max_size'] = '10000';
                $this->upload->initialize($config);

                if (!empty($_FILES['photo']['name'])) {
                    if (!$this->upload->do_upload('photo')) {
                        $error = array('error' => $this->upload->display_errors());
                    } else {
                        $data = $this->upload->data();
                        $ext = array_pop(explode(".", $data['file_name']));

                        $url_name = strtolower(url_title($name));
                        $new_name = 'upload/[mare] ' . $url_name . "." . $ext;
                        $new_name_th = 'upload/' . $url_name . "." . $ext;

                        $i = 2;
                        while (false && file_exists($new_name_th)) {
                            $new_name = 'upload/[mare] ' . $url_name . " ($i).$ext";
                            $new_name_th = 'upload/' . $url_name . " ($i).$ext";
                            $i++;
                        }

                        rename($config['upload_path'] . $data['file_name'], $new_name );


                        //create thumb -----------------------------------------------
                        $configg['image_library'] = 'gd2';
                        $configg['source_image'] = $new_name;
                        $configg['new_image'] = $new_name_th;
                        $configg['create_thumb'] = FALSE;
                        $configg['maintain_ratio'] = TRUE;
                        $configg['width'] = 120;
                        $configg['height'] = 120;

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

                        $this->image_lib->resize();
                        //echo $this->image_lib->display_errors();
                        //create thumb-----------------------------------------------

                        // resize big
                        $configg2['image_library'] = 'gd2';
                        $configg2['source_image'] = $new_name;
                        $configg2['new_image'] = $new_name;
                        $configg2['create_thumb'] = FALSE;
                        $configg2['maintain_ratio'] = TRUE;
                        $configg2['width'] = 800;
                        $configg2['height'] = 600;

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


                        $insert_arr['photo'] = basename($new_name_th);
                    }
                }

                $this->m_product->add($insert_arr);
                $id = $this->db->insert_id();
                //update prod_categ
                $subcategs = $this->m_subcategory->getAll();
                $update_prod_categ = array();
                foreach ($subcategs as $subcateg) {
                    if (isset($_POST[$subcateg->id_subcategory]) && $_POST[$subcateg->id_subcategory] == 1) {
                        $update_prod_categ[] = $subcateg->id_subcategory;
                    }
                }
                if (is_array($update_prod_categ) && sizeof($update_prod_categ) > 0) {
                    foreach ($update_prod_categ as $upc) {
                        $this->db->query("INSERT INTO prod_categ(id_product, id_subcategory) VALUES('$id','$upc')");
                    }
                }

                redirect('admin/product');
            }
        }

        $categs = $this->m_category->getCategsWidthSubcategs();
        $producers = $this->m_producer->getAll();

        $tpl_data['categs'] = $categs;
        $tpl_data['producers'] = $producers;
        $tpl_data['admin_title'] = 'Produse - Adaugare';
        $tpl_data['err'] = $err;


        $this->load->view($this->tpl_path . __FUNCTION__, $tpl_data);
    }

how can I modify this to upload another photo in the same tabel to field 'photo_2'




Theme © iAndrew 2016 - Forum software by © MyBB