SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Feb 2010
    Location
    Arkansas, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Image loads and then shows broken link

    Hello,
    I have an unusual problem in which I have been unable to figure out. On my website, in the HTML I have an image tag which loads an image from a PHP page. This image loads in the browser, and then is replaced by a broken link placeholder. It does this on every browser.

    If I browse to the image it displays just fine. It's just when I load it into a page that it breaks.

    Firebug gives me this error:

    Image corrupt or truncated: <image_url>
    Code HTML4Strict:
    <img src="ajax.php?action=chart&chart=projectCompletion" title="Click to view tabular data." />

    The ajax page grabs the data, and then sends it to Google's Charting API to be charted. I use header('content-type: image/png') and then output the image given back by Google using fpassthru(fopen()).

    This has worked fine for me for over a year. I recently moved to a new server and am currently porting my code to work on it. This was the first page I got working. I had another project which took priority and when I came back to this, it is no longer working. I've bashed my head out for two days trying to figure it out. Any ideas would be appreciated. Thanks!

  2. #2
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Temporarily remove the header('content-type: image/png), and visit the url directly in your browser (not via the img tag). Is anything dodgy (other than image nonsense output) being output?
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  3. #3
    SitePoint Member
    Join Date
    Feb 2010
    Location
    Arkansas, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, that was something else I tried. The code looks fine. There is no trailing white space (if that even matters). I even did a "Save Page As" and saved it as a PNG. No graphics viewer or editor even complain about it.

  4. #4
    SitePoint Guru r2d2's Avatar
    Join Date
    Dec 2003
    Location
    In my van, fool!
    Posts
    646
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is no white space being output anywhere? Is the open tag right at the start of ajax.php, and no close tag?

  5. #5
    SitePoint Member
    Join Date
    Feb 2010
    Location
    Arkansas, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The closing tag is definitely there.

    I think I am finally starting to figure out what is wrong. But I am not having any luck fixing it. According to PHP's documentation.

    If you do not specify the 'b' flag when working with binary files, you may experience strange problems with your data, including broken image files and strange problems with \r\n characters.
    So I put the 'b' tag in my fopen statement, but the browser still thinks it's a broken image.

    Here is my function:

    PHP Code:
    function chart_data($chartType$chartSize$chartData$visibleAxis$title$color$labels$margin) {
        
        
    // Create some random text-encoded data for a line chart.
        
    header('Content-Type: image/png');
        
    $url 'http://chart.apis.google.com/chart?chid='/* . md5(uniqid(rand(), true))*/;
        
        
        
    // Add data, chart type, chart size, and scale to params.
        
    $chart = array(
            
    'cht'    => $chartType,
            
    'chs'    => $chartSize,
            
    'chd'    => $chartData,
            
    'chxt'    => $visibleAxis,
            
    'chxs'    => "0,000000,10,0,lt",
            
    'chtt'    => $title,
            
    'chco'    => $color,
            
    'chxl'    => $labels,
            
    'chma'    => $margin
        
    );
        
        
    // Send the request, and print out the returned bytes.
        
    $context stream_context_create(array(
            
    'http' => array(
                
    'method' => 'POST',
                
    'content' => http_build_query($chart),
                
    'header' => "Content-Type: image/png\r\n")));
        
        
    // Send it to the requesting URL.
        
    fpassthru(fopen($url'rb'false$context));

    This issue only surfaced since I am moving from a Linux machine to a Windows machine.

  6. #6
    SitePoint Guru r2d2's Avatar
    Join Date
    Dec 2003
    Location
    In my van, fool!
    Posts
    646
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It would be best to remove the close tag from ajax.php - it doesn't need to be there, and you may end up outputing whitespace after it to the browser if it is in there.

  7. #7
    SitePoint Member
    Join Date
    Feb 2010
    Location
    Arkansas, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have a closing PHP tag.

    What I have figured out up to this point is that it actually was being truncated. I have now raised the output_buffer to 1MB, and the truncation is no longer a problem. [Although, this shouldn't have been a problem.]

    The bad thing is, that should have fixed it. Along with adding the 'b' into my fopen() and raising the output buffer everything looks fine. But, the browser still thinks it's either truncated or corrupt. I'm stumped. I'm going to post the straight up file output. Maybe you guys can look at it and see if something doesn't look right.

    Code:
    ‰PNG  IHDRU$ wbKGD “IDATxœyTSg˰/–ˆ* T pT .XVFqG‚ZǺ8V‘iZ[,Œ*v 0.EEA ”„dI’u‡h-o~›}ž$x{sRhu(€     ŠD0d–mlnn|ߩwpuu%––™L0dŠŠ …Bl?~ooa>‘fff^^^#8ŽŽŽ~{{{.LLL,,,F)€gŠ€•••gggSNŸ}…n6ŠUV[nQbbbSS‡‡188(ˆh``@[[;22rժUIOO/,,裏ž(‹šššYf=PAAݻr**mccDs”––VZZzA.q+ay`t{zz޻wV0;;[%77WOO˜vͽzjxxC‡9ƸqFŽYEEEGŽyn*jVVVjjjvv+sNXSŒ8cbbŸ?&aVhEnz*&L˜™™™3+**š››–œœ??'_[[7w%—/KҬŽˆž=}šˆ‰wlllDDDsssAAAXXS† ~Hœ'OžvUUU*\ƍ‰$..wa9z’’’—_~[o=‹5 ˆ=|$&&–––^šˆ<==---{•V"’J™™™sa:––VZZšH$:{JŠŒŒLLLܶm;‹[ZZNŸ>*RNœ8o‡Ÿ‰h7BBBRRR}]0Riww—j˜ՐիW‡††2`N›6-22’ˆšššR‰'ˆ˜9GBD...Dwޏ>(11gƒ6‡ٳ‡ˆV^|۷o{{{‘D"9z(ZJ&“q\!x6Lh)//wss**׷B[SSHD999Gnhh(--eN%&&‡K—jiiQaaŸŸŸ!iii-Z  @}ׯ•••;::2™Ν;LCDsMIIy|0Jr‘=‹/2Dl˜››fffhŽŽŽL@DZII‰L&{|Š0((ˆٶb`ƒ˜/Y_K€aLh˜-[0u"200˜3gNVVkVXXwšš.#q}SSSfC"‘ٱC.Nnoog‹prr’H$JœiVd###SSӺ:P~q}}@f^K+؁™OXXX(•J‰D‡ rppp``Qa0Ep„`dff[.<<œ*^b*[OŸ    O---…B™™s555C>œ™e"jmm055mmmej‰D’’’nݺG{`E.—Ÿ>}zڵ–––MMMl^MMMVVVWVOO*‡ss)S/‰9†<0*Š‹‹-ZĶLš4iCV(fžА’’|OD$‹œ9aܹ7z{{sssY’““™e‚s}7š†EWVV8p€ž‚L&ۿBXd‰Ÿ•žž~™3grŒ>==?š13=jj*q*’’’'– 0p`TdddN˜0Aq…;v`[~&o֬YK—.8e”ZWW5k֨w,((T[[;u_ˆ~`SS†††‘••UuuM›>0~C‡޽믿ikk366?\"}`ssŸ~w~O?MII011ٻw/—d;GGGGEE-]ֶ2::6*a "‘zܸq6RSSYWWW[[kkk~M€B(**wwwgID‰d›B*•ʲŽŽsss777SPnnnBDIII………~mmmP>&k‡SRݽ{šc0Š€gƒ[[[:aŠ†‡o c4vLL3„œBP(Ep‚    Ep‚8Aœ hNP4'(€     ŠEp‚8Aœ hNP4'(€ ‰F‹†ŠŠ MN#HECii&€„    Ep"|Z_*Œ#_sk38œ hNP4'(€     ŠEp4uuuQUUUvvT*uuu]xƒ 1))I}”;w666޹sgD}ƍh0EŠ†#GŽ„††;vƍ‹/233ƒ‚‚˜*c+++ʺSRR–.]š““;iҤtT%Š†ǻƍutt_z%GGG"rž#`rrƍ\\\ܤRi}}žžž••XdA ›xb333WWW"R*•NNN?9++kŒFFF“&MO:%‰"""Ÿ?b [GGGkk+’F€‘ hw^LLŒ‰‰'Ÿ|biiCDgœquu ̾›7o޽›ˆALLLccM}}***K—4œŒ†6N›6p™UUUD”–––žž?iZZZCž™ŸŸ?m4H==K—.$%%kii>}P“zpŸ8qH$bE"‘……EmmmyyyLLŒۻS&“17okowqss™3gŽSSg„‘‘|`llsڵ-[0„BڵkCBB<==RiGG‡XJL#GŽ(•ٳgk8% Z*•Šinn–d/Fp!—%‰……{}@`jjvp«~ec_snV€g‡@}ŒVDdiikF€ n# œ hNP4'(€ ‰Œ(NixF8œ hNP4'oŒ#}ܸqců?!…Rs|Ÿ~)‚?Aafff.Œ#…Hal=~B O0?VRxXžNt٣ …Ʀ Ha=~B O0?=“)Ÿx.Oˆb…BGŠRewU*Uwwˆb™L.…ngHRRl.…––––––N…w)Q˯$I‹/‚_)‘D"dwy?uwwī~X&•JrcF\ѰfšW^yE(kl‘rԩxfD(!!!Ÿ›VPPPHHˆC‡ˆo)+WLKK#‹•••”Je–-[sNa D׿u޼yӧOOII!peTYYɯ‚ƒƒ—-[}E[ ‹-Z‘——G|KDzw}wŸ*BCCU*UIIٳ53H 266Ževƒƒƒ^R|ͯjLC$555::ZRM˜0A*•+…„„„}T*š5kƏ_^^a 555K–,Qo] o RTbx•**((W-…gϮ_^R555    …BWTs,hhh˜>}ŠW)<XA4tڵk, —^zI$xu!7|sAvhD`‚ׯ]\\yzzn޼™ˆ‹_),[l† …žxQrr”)S\\\˜]ޥPUU߿~-[444St‹œ9““““ššJR b[[[333f—_)d2P$”J\.WDtʱX{vvv€w)†DΦ^x…Ÿ‘/Tro3f̸xf&AŽc/™1c›gœ7qamm+…277—_~y*€€BHޥPQQ9gœxSdk׮gœy—‚Jڷo_BB˯jkk=<<6l0o޼ݻwJjkkswwŒŒW-…BCC|͹s†͝ EQQ‘ff=***"‘“L•Boooyy‡‡_‹w)3ע1-KAT[YY9880-KaJA&“•””SWRRbbb´.‘›››O˜0QO!€`p‚8?[—UߦIENDB`‚

  8. #8
    SitePoint Member
    Join Date
    Feb 2010
    Location
    Arkansas, USA
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, now I finally have been able to fix it. But oddly enough, I'm not sure what breaks it. Let me explain.

    At the beginning of the page I do:

    PHP Code:
    $auth = new class_auth(); 
    This class has an optional parameter in which I can pass the page name to see if the user has access. If I do not pass the parameter, it gives the user access by default.

    I found out that if I comment out this line of code the images work. I also found out that if I go ahead and pass it a parameter of a page name that I have access to it also works. This means the browser doesn't complain about the images either way.

    So, after figuring that out I decided to take a look at the code in my auth class again. If I do not pass a parameter, the only thing that is done is session_start() and then it returns true.

    Considering this has been this way for over a year, I am highly doubtful that the session_start() is messing me up. I am ultra confused.

    Does anyone have any ideas?

    P.S. To clarify: the browser dislikes the images ONLY if I do not pass the optional parameter.


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
  •