Menu

Cant for the life of me get away from broken image

2015-01-26
2015-01-27
  • ThunderAeroInc

    ThunderAeroInc - 2015-01-26

    SOLVED: File format of script must not contain a BOM. ANSI encoding is an example of the file format which works.


    I am unable to get even the most basic example working and for whatever reason PHP wont generate an error telling me why.

    I am doing this:

    <html>
    <head>
    <title></title>
    </head>
    <body>
    
    <img src= 'ADMIN_settings2.php' >
    
    </body>
    </html>
    

    ADMIN_settings2.php....

    <?php
    require 'phplot.php';
    $data = array(array('', 10), array('', 1));
    $plot = new PHPlot();
    $plot->SetDataValues($data);
    $plot->SetTitle('First Test Plot');
    $plot->DrawGraph();
    

    phplot is located in the same directory as the scripts.

    Here is what phpinfo says:
    GD Support enabled
    GD Version bundled (2.1.0 compatible)
    FreeType Support enabled
    FreeType Linkage with freetype
    FreeType Version 2.4.10
    GIF Read Support enabled
    GIF Create Support enabled
    JPEG Support enabled
    libJPEG Version unknown
    PNG Support enabled
    libPNG Version 1.5.14
    WBMP Support enabled
    XPM Support enabled
    libXpm Version 30411
    XBM Support enabled
    WebP Support enabled

    Php is 5.5.6, phplot is 6.1

    Running the script in CLI yields a header issue related to phplot lines 1839, 1840, 1841, 1842, 1858 and junk being displayed (which is probably normal).

    Running it with the > output.png flag displays nothing but the image cant be opened because the headers are messed up with an 'Improper Image Header'

     

    Last edit: ThunderAeroInc 2015-01-27
  • lbayuk

    lbayuk - 2015-01-26

    (Aside: I edited your post to put "code block" markers around the HTML and PHP code, because otherwise it doesn't display properly.)

    I can't see anything wrong with what you posted, and your PHP script runs for me and generates a plot image.

    I don't know why you would get 'header already sent' messages when running a script with the PHP CLI, as I thought headers are ignored in the CLI.

    Anyway, first check for easy stuff. Make sure there are no spaces or blank lines in ADMIN_settings2.php before the PHP open tag.

    If possible, check the web server error log after trying to run the script from the web site.

    If we're still stuck at this point, run it from the CLI as you did with output redirected to a file, and take a look at the first few dozen bytes in the file with a hex dump or something like that. Because I think something is being output before the image and it would be helpful to know what it is.

     
  • lbayuk

    lbayuk - 2015-01-26

    Never mind, forget what I said about headers and the CLI. Just tried it, and although the CLI doesn't output headers, it does complain if anything else is output before header(). So yes, as you said, you will get those header warnings if anything is output first.

     
  • ThunderAeroInc

    ThunderAeroInc - 2015-01-26

    Well, that is all very strange. I dont know what is in the buffer for headers prior to the file as there is nothing in the file themselves. All I did was copy and past the contents directly to the forums here and as you said it works for you.

    I am using Xampp which shouldn't be an issue as Ive seen posted on the internet saying its worked in Xampp but not other CMS sites.

    The web service log records nothing. I have tested it by manufacturing bad code and it records the error to the log, but nothing from Phplot gets recorded. No error graphics, no errors at all other than the broken image.

    GD settings appear correct, Error log settings in PHP appear correct. Tried it on two different computers and still an error. I could try it on an older version of PHP, but I doubt that would make a difference.

    I even tried to use the header_remove() function in php to strip the headers and still a broken image results.

    Placed the output.png into a HEX editor. You can probably guess what it looked like. The first 490 lines are all error Headers already sent messages. I have no idea how they are getting there though.

    Checked different version of PHP and xammp and it still does not work.

    When Admin_settings2.php is looked at in chrome it looks like this:

    <html><head><meta name="viewport" content="width=device-width, minimum-scale=0.1"></head><body style="margin: 0px;"></body></html>

     

    Last edit: ThunderAeroInc 2015-01-27
  • lbayuk

    lbayuk - 2015-01-27

    Your troubleshooting skills are excellent, but what helped was attaching the files. Both of these files start with Unicode Byte Order Markers (BOM), which is a 3-byte sequence, in hex: EF BB BF. This tells some programs that the rest of the file is encoded in UTF-8. Unfortunately, not every program understands and allows Unicode BOMs. I really think this is the problem.

    I need to read up on this and try it with PHP, but for now I think you should try removing the BOM prefix from the ADMIN_settings2.php script. I wish I could suggest how, but I'm not really sure - it probably depends on what text editor you are using.

     
  • ThunderAeroInc

    ThunderAeroInc - 2015-01-27

    What encoding should it be in?

    Well, Holly... Placing it into ANSI and it worked like a charm.

     

    Last edit: ThunderAeroInc 2015-01-27
  • lbayuk

    lbayuk - 2015-01-27

    I just tried php-5.6 and php-5.5 and both treat the Byte Order Marker as regular text. So if a script starts with a BOM, it will be copied as regular text before the script runs. The characters themselves are invisible, but PHP knows something was emitted before headers, hence the errors.

    I'm still going to look into this. I've never heard of it before, but I'm sure somebody has run into it.

     
  • ThunderAeroInc

    ThunderAeroInc - 2015-01-27

    With all of that out of the way...

    Now to get the sample working on the real page, which it doesn't...

     

    Last edit: ThunderAeroInc 2015-01-27
  • lbayuk

    lbayuk - 2015-01-27

    For reference: https://bugs.php.net/bug.php?id=22108 "PHP does not ignore the UTF BOM" describes this issue. It was written in 2005 and marked "Won't fix".

    And to correct myself: it's Byte Order Mark (BOM), not Byte Order Marker.

     
  • ThunderAeroInc

    ThunderAeroInc - 2015-01-27

    Good to know. Everything is working now. What an excellent solution for charts. Took long enough to get there, but its all good now.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.