0

I'm showing my images with php.

function showImage( $id = 0 ){

        $img = $this->db->where('id' ,  $id )->get('images');
        $src = base_url('files').'/'.$img['filename'] ;

        $ext = explode('.' , $img['filename']);

        switch( end($ext) ) {
            case "gif": $ctype="image/gif"; break;
            case "png": $ctype="image/png"; break;
            case "jpeg":
            case "jpg": $ctype="image/jpg"; break;
            default:
        }

        header('Content-type: ' . $ctype);
        echo file_get_contents($src);
}

It works fine when I put address directly in the browser , but when I call it with fancybox it show a very big screen with nothing in it and I get lots of

���F���!1AQ"aq� 2��#B��R�3�$r��Cb�%&4c�����������������������#�������!1AQa2"q������?��P�����������

In the firebug in response to fancybox ajax request.

max
  • 3,614
  • 9
  • 59
  • 107
  • http://stackoverflow.com/questions/35879/base64-encoding-image Maybe this will help you – user2718671 Apr 08 '14 at 13:17
  • You're exploding the filename but then testing the array, instead of the last index of the array $ext which is the actual file extension. YOu want switch($ext[count($ext) - 1]) – xd6_ Apr 08 '14 at 13:25

2 Answers2

0

I had a similar issue and found fancybox doesn't always play well with dynamically generated images. My solution was a rewrite in .htaccess. I was using .net with isapi rewrite but the rule will be similar. It was something like

/([0-9])/([^/.]+).(jpg|gif|jpeg|png)$ /image.ashx?id=$1&filename=$2&extension=$3

This did the trick for me. (the image.ashx would be your php file)

mrpotocnik
  • 1,101
  • 1
  • 10
  • 15
0

i've solve it by adding

  "type":"image"

to fancybox config

max
  • 3,614
  • 9
  • 59
  • 107
  • We normally prefer the tray/error method first instead of reading the documentation ;) http://fancyapps.com/fancybox/#support ==> FAQ tab ==> No.5 – JFK Apr 08 '14 at 18:29