Results 1 to 3 of 3

Thread: PHP compatibility issue with 64-bit Windows machine on php GD library?

  1. #1
    Join Date
    Jan 2008
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default PHP compatibility issue with 64-bit Windows machine on php GD library?

    Greetings to all,

    I have a problem displaying an image on the Web. My environment is PHP 5.2.8, 64-bit Operating System. Windows Server Standard SP1 and is using php5isapi.dll: ISAPI v4.0.

    <?php
    //require 'config.php';
    $image = imagecreate(200, 110);
    $bg = imagecolorallocate($image, 225, 0, 0);
    $color = imagecolorallocate($image, 255, 255, 255);
    imageline($image,10, 10, 60, 60, $color);
    header("Content-type: image/png");
    imagepng($image);
    ?>

    config.php is a standard php file in the same directory.
    <?php
    $myvar1='some value';
    ?>

    The problem is if I require(require_once, include) config.php at the beginning of the script(see the red colored line above), the browser gives me the error "The image “http://www.myserver.com/DrawALine.php” cannot be displayed, because it contains errors.". If I comment this line out or move it to the end of the script, the image shows up.

    I understand that header must be sent to browser before anything else, even a space character. I double checked to make sure there is no spaces in the script before header("Content-type: image/png");

    When I copied the same code to a 32-bit windows machine. It worked.

    As far as I can tell, the only difference between my 2 test machines is one is 32-bit and the other is 64-bit.

    Can somebody here shed some light on it?

    Any suggestions will be greatly appreciated,
    Last edited by dogshasha; 02-03-2009 at 09:18 PM. Reason: Resolved

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's not just that the header must be sent before anything else. PNG is a binary format, and therefore very fragile. If anything other than the image data is output, at any point, it will fail with the error you just described. In Firefox, you can go to View->Page Source to see the output in text form, which may shed some more light on the issue. Since it happens on one machine and not another, I suspect that config.php throws an error on that machine, which PHP outputs, thereby messing up the image. It's also possible, though, that there's just some trailing whitespace in config.php which you didn't copy over.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. The Following User Says Thank You to Twey For This Useful Post:

    dogshasha (02-03-2009)

  4. #3
    Join Date
    Jan 2008
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Thanks, Twey. It's solved.

    You are correct. It's the problem with config.php. Although I double checked this file and thought I made sure there is no weird characters in this file, apparently there are weird characters in it. I deleted it and created a new one. Then the problem is solved.

    Thank you so much,

    Quote Originally Posted by Twey View Post
    It's not just that the header must be sent before anything else. PNG is a binary format, and therefore very fragile. If anything other than the image data is output, at any point, it will fail with the error you just described. In Firefox, you can go to View->Page Source to see the output in text form, which may shed some more light on the issue. Since it happens on one machine and not another, I suspect that config.php throws an error on that machine, which PHP outputs, thereby messing up the image. It's also possible, though, that there's just some trailing whitespace in config.php which you didn't copy over.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •