Be really appreciated if someone could point me to the right direction.
Trying to create a widget to display images under the "Protected area" which usually involve "readfile", I can sort of get the function to work under when place under a controller, but as soon as I tried to make it into a re-usable widget, I am unable to get any image to display (but then again i am pretty new to widget and yii)
widget main file
<?php
class ProductImage extends CWidget {
public function init()
{
}
public function run() {
$this->render('ProductImage_');
}
//returns html code with iamges.
public function GetImagesForProduct()
{
$path_to_file = "/opt/lampp/htdocs/project/protected/clientfolder/product/32/";
$imagefiles = $this->listImages($path_to_file); //returns in an array();
if(sizeof($imagefiles)>0)
{
foreach($imagefiles as $filename)
{
echo "<img src='".$this->GetSingleImage($path_to_file.$filename)."'>";
}
}
}
public function GetSingleImage($path_to_file='')
{
if(file_exists($path_to_file))
{
$img=getimagesize($path_to_file);
header('Content-Type: '.$img['mime']);
readfile($path_to_file);
}
}
public function listImages($dirname=".") {
$ext = array("jpg", "png", "jpeg", "gif");
$files = array();
if($handle = opendir($dirname)) {
while(false !== ($file = readdir($handle)))
for($i=0;$i<sizeof($ext);$i++)
if(strstr($file, ".".$ext[$i]))
$files[] = $file;
closedir($handle);
}
return($files);
}
}
?>
The view file, neither of the two will work
<div id="productimage">
<?php
echo $this->GetImagesForProduct();
?>
</div>
<div id="productimage">
<?php
echo "<img scr='"$this->GetImagesForProduct()."'>";
?>
</div>
Output
The image cannot be displayed because it contains errors.
and if I remove the header('Content-Type: '.$img['mime']); I will get what seems to be the image of a base64 string which I can't display using base64_encode().
Thanks in advance

Help












