Content-Type:用于OpenCart ajax模板文件的image / jpeg

时间:2013-12-11 13:35:01

标签: php opencart content-type

以下是图库页面的img标签,它纯粹是动态的,图像源会重复更改,

<img src="index.php?route=common/ajax/displayimage&amp;image=<?php echo urlencode($image['artwork']); ?>" />

它在ajax控制器中调用displyimage()。以下是ajax页面的内容

public function displayimage() {

    $img = urldecode($this->request->get['image']);
    $list = explode(".", $img);
    $this->data['ext'] = end($list);
    $this->data['image'] = $img;

    header('Content-Type: image/jpeg');

    // We call this Fallback system
    if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/common/display.tpl')) {
        $this->template = $this->config->get('config_template') . '/template/common/display.tpl';
    } else {
        $this->template = 'default/template/common/display.tpl';
    }

    $this->response->setOutput($this->render(TRUE));

}

下面是ajax的tpl文件,我选择如何显示图像,

if($ext == 'png') {
    $img = imagecreatefrompng($image);
    imagejpeg($img);
}

if($ext == 'jpeg' || $ext == 'jpg') {
    $img = imagecreatefromjpeg($image);
    imagejpeg($img);
}

if($ext == 'gif') {
    $img = imagecreatefromgif($image);
    imagejpeg($img);
}

if($ext == 'psd') {
    $img = imagecreatefrompsd($image);
    imagejpeg($img);
}

但是内容类型在这里不起作用。此外,图像功能不会产生图像。我做错了什么?

0 个答案:

没有答案
相关问题