url shortend machanism by javascript

Advertisements

upload image through ajax jquery php codeigniter

    public function save_product_detail_image($idproduct)
    {
        if (isset($_POST['image'])) {

            $imageData = $_POST['image'];

            list($type, $imageData) = explode(';', $imageData);
            list(,$extension) = explode('/',$type);
            list(,$imageData)      = explode(',', $imageData);
            $fileName = uniqid().'.'.$extension;
            $imageData = base64_decode($imageData);
            file_put_contents('assets/produkt_images0/'.$fileName, $imageData);

            if ($_POST['id_file_type'] == "master_img") {

                $this->db->where("id_product", $idproduct)
                ->where('id_file_type', 'master_img')
                ->delete('file');
            }
            else if ($_POST['id_file_type'] == "product_featured_img") {

                $this->db->where("id_product", $idproduct)
                ->where('id_file_type', 'product_featured_img')
                ->delete('file');
            }

            $file_produkt_image = array(
                "id_file_type" => $_POST['id_file_type'],
                "id_product" => $idproduct,
                "is_active" => 1,
                "file_name" => "assets/produkt_images0/" . $fileName,
                "thumb_name" => "assets/produkt_thumb0/" . $fileName,
                "file_description" => 'hl. obrazek produktu',
                "created_by" => 2,
                'modified_by' => 2
            );

            $this->db->insert('file', $file_produkt_image);

            return $fileName;
 
        }
    }