我在一个类中有一个简单的函数:
<?php>class cre { function creimage() { header("Content-type: image/gif"); $im = imagecreate (100, 50); imagegif($im); imagedestroy($im); } };?>在模型文件中:
<?php class mymodel extends JModel { var myclass; function __construct() { myclass = new cre(); } function getMyclass() { return $this->myclass; } };?>view.html.php文件:
<?php class myview extends JView { function display($tpl = null) { $myclass = & $this->get('Myclass'); parent::display($tpl); } };?>我在joomla模板中调用此函数,给出了image标签的src属性,如下所示:
<img src='<?php echo $this->myclass->creimage();?>'>
但是,尽管我得到了图像,但我可以在浏览器中看到图像的二进制代码。 错误是什么? 非常感谢
I have a simple function in a class:
<?php>class cre { function creimage() { header("Content-type: image/gif"); $im = imagecreate (100, 50); imagegif($im); imagedestroy($im); } };?>In model file:
<?php class mymodel extends JModel { var myclass; function __construct() { myclass = new cre(); } function getMyclass() { return $this->myclass; } };?>view.html.php file:
<?php class myview extends JView { function display($tpl = null) { $myclass = & $this->get('Myclass'); parent::display($tpl); } };?>I call this function in a joomla template with giving src attribute of image tag such manner:
<img src='<?php echo $this->myclass->creimage();?>'>
but in spite of I get the image, I can see the binary code of the image in the browser. What is the error? Many thanks
最满意答案
您的creimage方法正在发送实际的图像数据,这些数据是您在src=''属性中所固定的,这将无效。
您需要在src属性中放置一个URL:
<img src='/path/to/imagescript.php'>然后在那里创建一个PHP脚本,使用适当的标头发送图像数据。
Your creimage method is sending out the actual image data, which you are sticking inside of your src='' attribute, that won't work.
You need to put a URL in the src attribute:
<img src='/path/to/imagescript.php'>Then create a PHP script there that sends out the image data with the appropriate header.
更多推荐
image,function,php,电脑培训,计算机培训,IT培训"/> <meta name="descriptio
发布评论