The following PHP-script should display a gif-image in the browser. On a unix-server it does, but on my laptop /XP it does not. Why??

<?
$filespec="images/blume.gif";
$fp = fopen($filespec,'rb');
$contents=fread($fp,filesize($filespec));
header('Content-Type: image/gif' );
echo $contents;
?>

I have apache2 installed on my laptop.
I would appreciate your help 😕

    Originally posted by stefan000
    The following PHP-script should display a gif-image in the browser. On a unix-server it does, but on my laptop /XP it does not. Why??

    <?
    $filespec="images/blume.gif";
    $fp = fopen($filespec,'rb');
    $contents=fread($fp,filesize($filespec));
    header('Content-Type: image/gif' );
    echo $contents;
    ?>

    I have apache2 installed on my laptop.
    I would appreciate your help 😕

    Well, I see two possibilities right off.

    First, let's make sure we're not having some type of filesystem difficulty. Try this:

    <?php
    $filespec="images/blume.gif";
    if (!is_file($filespec)) {
       die("It's not a valid file!");
    }
    $fp = fopen($filespec,'rb');
    $contents=fread($fp,filesize($filespec));
    header('Content-Type: image/gif' );
    echo $contents;
    ?>

    The second possibility is that your laptop's PHP wasn't compiled with/doesn't have the gd library, or if it does, it has a version without GIF support. That's obviously a much more complex issue...what does

    <?php
    phpinfo();
    
    ?>

    tell you?

      Originally posted by dalecosp
      Well, I see two possibilities right off.

      First, let's make sure we're not having some type of filesystem difficulty. Try this:

      <?php
      $filespec="images/blume.gif";
      if (!is_file($filespec)) {
         die("It's not a valid file!");
      }
      $fp = fopen($filespec,'rb');
      $contents=fread($fp,filesize($filespec));
      header('Content-Type: image/gif' );
      echo $contents;
      ?>

      The second possibility is that your laptop's PHP wasn't compiled with/doesn't have the gd library, or if it does, it has a version without GIF support. That's obviously a much more complex issue...what does

      <?php
      phpinfo();
      
      ?>

      tell you? [/B]

      1. It is a file
      2. I checked phpinfo, but don't know where to find this information.
        Nevertheless, thanks!! :queasy:

        Well, there should be a section in the output of phpinfo() that has a header like "gd" ... if not, then you have no graphics support anyway. Within the "gd" section, look for "gif read support" and "gif create support" and see if they're enabled.

        Now then, on second glance, even if you do have gd support, I'm not sure you'd get it working with [man]echo[/man]. Look at the image functions --- specifically, I'd think you'd want [man]imagegif[/man] where you currently have the echo. A short example:

        //source image
               $file="images/foo.gif";
               $sourceimg=imagecreatefromgif($file);
        
        // prepare a canvas
        $new_img=imagecreatetruecolor($new_width, $new_height);
        
        // let's say we're making a thumbnail....
        
        imagecopyresampled($new_img, $sourceimg, 0,0,0,0, $new_width, $new_height, $width, $height);
        
        // Output the photo
        
        header("Content-type: image/gif");
                Imagegif($new_img);
        

        Something like that ...

          Finally, after changing my php.ini-File using php.ini-dist instead of php.ini-recommended, my script is working. I don't know yet the directive responsible for the problems.

          After including the graphics library 'php_gd2.dll', which was not before, your script did not work because of the unknown function

          imagegif();

          It seems to be deprecated in my version of gd.

          Thanks a lot for your hints.
          🙂

            Write a Reply...