2013-09-21 116 views
0

我想添加一個自定義圖像字段來上載opencart的數據選項卡中的圖像。圖像顯示,但點擊保存按鈕後,圖像消失,圖像也沒有保存在MySQL數據庫中。所以請幫助我。 我改變現有的代碼如下上傳圖片:在Opencart的數據選項卡中添加自定義圖像字段

在控制器/目錄/ product.php

if (isset($this->request->post['backgroundimage'])) { 
     $this->data['backgroundimage'] = $this->request->post['backgroundimage']; 
    } elseif (!empty($product_info)) { 
     $this->data['backgroundimage'] = $product_info['backgroundimage']; 
    } else { 
     $this->data['backgroundimage'] = ''; 
    } 


    $this->load->model('tool/image'); 

    if (isset($this->request->post['backgroundimage']) && file_exists(DIR_IMAGE . $this->request->post['backgroundimage'])) { 
     $this->data['thumb'] = $this->model_tool_image->resize($this->request->post['backgroundimage'], 100, 100); 
    } elseif (!empty($product_info) && $product_info['backgroundimage'] && file_exists(DIR_IMAGE . $product_info['backgroundimage'])) { 
     $this->data['thumb'] = $this->model_tool_image->resize($product_info['backgroundimage'], 100, 100); 
    } else { 
     $this->data['thumb'] = $this->model_tool_image->resize('no_image.jpg', 100, 100); 
    } 

鑑於/模板/目錄/ product_form.tpl

<tr> 
       <td><?php echo $entry_backgroundimage; ?></td> 
       <td><div class="image"><img src="<?php echo $thumb2; ?>" alt="" id="thumb2" /><br /> 
        <input type="hidden" name="image2" value="<?php echo $backgroundimage; ?>" id="image2" /> 
        <a onclick="image_upload('image2', 'thumb2');"><?php echo $text_browse; ?></a>&nbsp;&nbsp;|&nbsp;&nbsp;<a onclick="$('#thumb2').attr('src', '<?php echo $no_image; ?>'); $('#image2').attr('value', '');"><?php echo $text_clear; ?></a></div></td> 
      </tr> 

在模型/目錄/ product.php

$this->db->query("INSERT INTO " . DB_PREFIX . "product SET backgroundimage = '" . $this->db->escape($data['image2']) . "',product_id = '" . (int)$product_id . "'"); 

回答

0

而不是 $this->db->escape($data['image2']) 使用本 $this->db->escape(html_entity_decode($data['image2'], ENT_QUOTES, 'UTF-8'))

相關問題