-1

我的脚本几乎可以工作,但是当我运行 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”

4

1 回答 1

0

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

<img src='<?php echo base_url(); ?>img_folder/<?php echo $string; ?>/1' 
width="100px">
于 2012-08-10T14:18:07.547 回答