-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);

    }

これは、ヘッダーが再送信されたことが原因である可能性があると思われます。そうであれば、どうすれば解決できますか。

乾杯

問題を修正 - 「ホットリンク」を使用

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 に答える