安全图像失败 - Codeigniter

时间:2012-08-10 12:59:06

标签: php codeigniter

我的脚本非常有用,但是当我运行for循环时,它在视图中失败了:

<?php foreach($pics as $index=>$pic){?>
            <td class='Pictures'>
                <center>

                <?php

                $piece = explode('/',$pic["ThumbImg"]);
                $string = $piece[5];



                ?>
                <img src='<?php echo base_url(); ?>index.php/Controller/getImage/<?php echo $string; ?>/1' width="100px"> 

                </a>

控制器类 - 获取图像功能:

//function to protect images from being accessed directly by obfuscating the URL
    function getImage($img_id,$type){

    if($this->members->logged_in()){    

          //code to authenticate user goes here then...

    //code to decide which type of file it is/thumb/full size image
    if($type==1)
    {
    $url = $this->data['base_url'].'system/application/images/pic/thumbs/';
    }else if($type==0){

    $url = $this->data['base_url'].'system/application/images/pic/';

    }

    $filepath = $url.$img_id;


    //send image to web browser.
        header("Content-type: image/jpeg");

      //get path
            $img_handle = imagecreatefromjpeg($filepath) or die("");
       //create and send     
        ImageJpeg($img_handle);

    }

我怀疑这可能是由于标题被重新发送,如果是这样,我该如何解决这个问题。

干杯

解决了问题 - 使用了“Hotlinking”

1 个答案:

答案 0 :(得分:0)

如果您要从数据库加载图像,基本上只需要设置标题信息header("Content-type: image/jpeg")。但是,既然你从文件夹中加载它,你可能想跳过php文件并立即从文件夹中获取图像:

<img src='<?php echo base_url(); ?>img_folder/<?php echo $string; ?>/1' 
width="100px">