Jalz Posted April 27, 2010 Share Posted April 27, 2010 Hi all, Just wanted to know if you can point us in the right direction. I have created a folder on the c drive outside my wwwroot folder called myImages and am trying to output the data on my webpage. The ImageURL field contains the pathname, so it would contain "c:\myImages\nameofimage.png" I have the following code, and the webpage is just showing garbage, any ideas what I am doing wrong? Many Thanks all J <?php $filePath = $MyDetails_row->getField('ImageURL'); echo $filePath; header('Content-type: image/png'); header('Content-length' . filesize($filePath)); readfile($filePath); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/ Share on other sites More sharing options...
Ken2k7 Posted April 27, 2010 Share Posted April 27, 2010 Remove the echo $filePath; line. And try this: Replace the $readfile($filePath); with: echo stream_get_contents(fopen($filePath, "r")); Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049366 Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 You can use a shorthand for that and use file_get_contents: echo file_get_contents($filePath); Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049369 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Hi Guys, Thanks for this, sorry the echo $filePath; was there as a mistake, just making sure it had the correct path. Tried both of the code options and both interestingly give me the same 'garbage' briefly looking at it. I definately have png file stored in that location as I thought it was the header details. Any other ideas? This is what I have tried so far Many Thanks $filePath = $MyDetails_row->getField('ImageURL'); header('Content-type: image/png'); header('Content-length' . filesize($filePath)); echo stream_get_contents(fopen($filePath, "r")); or $filePath = $MyDetails_row->getField('ImageURL'); header('Content-type: image/png'); header('Content-length' . filesize($filePath)); echo file_get_contents($filePath); Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049375 Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 header('Content-length' . filesize($filePath)); You're missing the : after Content-length Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049377 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Thanks de.monkeyz, should have looked harder at the headers- had a feeling it was there. OK, got rid of the garbage but now I get the infamous red cross (which you get on sites with images missing). again checked filePath to make sure it has "c:\myImages\myimagename.png" in it, which it does. Any else Im doing which I shouldn't be? J Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049384 Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 If you comment out the headers temporarily. Does it echo out gibberish (i.e the binary for the image)? Or are there some errors in there too? Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049385 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Yes if I comment out the headers, it does have gibberish... Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049388 Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 Well it seems to be grabbing the image data correctly then. So there's no other output occurring on this page except the image output? Including <html> and <head> tags, just to make sure. (Try viewing source in your browser) Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049389 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 ignore what i just said - headers were still commented out.....let me try again Mmm.... viewing source only has the following ‰PNG Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049391 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2010 Share Posted April 27, 2010 For debugging purposes, add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049392 Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 If view source is only showing that, the png image seems to be empty. That I THINK is just the binary code of the start of any png (I just tried the code with my own png and it showed that at the start). Since there should be A LOT more output than that This is the type of output you'd have Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049394 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Hi Guys, This is what the output is saying.... <HTML><HEAD> <META content="text/html; charset=windows-1252" http-equiv=Content-Type></HEAD> <BODY><IMG src="http://localhost/the_folder/testdisplayimage.php"></BODY></HTML> I'll put the errors messages on and test with some other images; got to head out for a meeting now thank you so much for your helps guys - hoping to suss this out later..... Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049400 Share on other sites More sharing options...
litebearer Posted April 27, 2010 Share Posted April 27, 2010 perhaps it might be time to test the image itself. 1. temporarily put a copy of the png file in the same folder as your php script 2. make a simple php script <?PHP $file = "nameofimage.png"; ?> <IMG src="<?PHP echo $file;?>"> <?PHP ?> if its a valid image file it should display. If it does display, then is it possible that PHP cannot access the 'above root folder"? (you also might create a simple txt file in the 'above root folder' and do another test where you create a simple php script to read the txt file) ie the old standby 'Hello, World' just an old guy's musings Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049511 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Hello again, I'm back and i've decided to change the imagetype to jpg for testing purposes to see if it behaves differerently. my new code is now $filePath = $MyDetails_row->getField('ImageURL'); header('Content-type: image/jpg'); header('Content-length:' . filesize($filePath)); echo file_get_contents($filePath); I've also turned errors on the page like PFMaBiSmAd suggested. In I.E 8 I do get garbarge like what you showed but no image. In FireFox I just get http://localhost/foldername/testdisplayimage.php displayed in my browser. When you did your test, were your images outside the webroot folder? Thanks Jalz Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049517 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2010 Share Posted April 27, 2010 Post the 'garbage' you are getting. Some people's garbage is someone else's clue. I suspect that magic_quotes_runtime is on and the binary data is being escaped, thereby breaking the image data. Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049521 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Hi litebearer, Your code works ok, when the image is in the same folder as the script. Jalz Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049522 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 ok here goes, this is from the jpeg version as the png dont even display this but works ok when the png is in the webroot folder I'll only attach a page worth of garbage as im sure you dont want all of it? Thanks all again ÿØÿàJFIFHHÿá®ExifMM*bj(1r2Ž‡i¤Ð ü€' ü€'Adobe Photoshop CS3 Windows2010:04:23 13:02:43 Ö &(.xHHÿØÿàJFIFHHÿíAdobe_CMÿîAdobed€ÿÛ„ ÿÀ+ "ÿÝ ÿÄ? 3!1AQa"q2‘¡±B#$RÁb34r‚ÑC%’Sðáñcs5¢²ƒ&D“TdE£t6ÒUâeò³„ÃÓuãóF'”¤…´•ÄÔäô¥µÅÕåõVfv†–¦¶ÆÖæö7GWgw‡—§·Ç×ç÷5!1AQaq"2‘¡±B#ÁRÑð3$bár‚’CScs4ñ%¢²ƒ&5ÂÒD“T£dEU6teâò³„ÃÓuãóF”¤…´•ÄÔäô¥µÅÕåõVfv†–¦¶ÆÖæö'7GWgw‡—§·ÇÿÚ?ÊoÕÞ°^ €a¶>¦Œ±ß÷ÔFýZêÏqÚÊìv€·{xìàáù‹ªÆÇ7[E,k=[ cÙ$†ºÝ³ýJÖƒúF]uÙcv1¬a/s¶8éîq~áÿ~U‘Ô«pðÇBǺ¦=˜½Vú.o§m>×°þk‡æ¨0°·Ê~Œr~—µo}yé·¬fÌf¶×åc×{«dHÚÏJÛ!¤·gè4ãe.÷·ná-âîæv»û*hë|òù›aÍk¤KgXCÄnëعÁ¢u]ùüûSŒ†8¶±¡$4Èît•§Ð1.¯¨YŒôZí¯sijw¨k¨¿¥g»Õúýž¢= ¢.A>WIÍ¡þ¥”œÌbgsZCˆ˜-{gô^àªUÐ_‹Mw]‹Huµmõvmmý)eo}5»ôŸ¾»ŒÌ^›õzÜ‹Y™Ó ½”Uê6ÆÝc†Ìv6¼íù>Ýk¶Yú/ç=K=J×-Òq²nÇ·2îcì™ ª_sXÆï¯~ö;Òö;zhâÔŽŒ²kt~µ}Y£§ôÜ{1jÍõé±µ]n[Úíõ¿#~8cŸüÆÍ–¬—Cœ×I‡Äêþêéþ¿dõ,z0:xõëé×T.smq±Û›S+ÈŸµµú5ÛUO}žû=[žû–Õ¾œü̯LZ1i6mȽà¸5°Øk)öî³wç»ù´<6VH:}'.ì‹šç;qnÖ´aãvÈ>ýîÜ»«®¹õúnªÂÚÛ\櫓¯e>›¿GOÐwæ³þ s¹?Qs°rVæêA—:ç ÖRïgÚéì¦ßOÕoæzÕÚ·c)¿Qr¬i»Ê1M-¶ßlÛ¸ þϵﻦÌûgØš`dA®‹âc›ÐÚùÇTeæåg‡ÐËžcCZ>—æ1›}Ÿ˜ÅRª®tÖÀ_k†Ö°N³ôyZtl¼‚Â×c¸9ÛM6XXö’}1»c}»Ÿüß»ÓWú%UfŠ3hs¡®9°÷?éz›v4ú;w{íÛìÿH¤7ÃñK³[¦õ“m®Ãsê£vŒ-iœË\í¯þ¯Ó]Fú›Óº¯KÕmyŽ’ÖÏL8ôÝTz›?—½7X¥9”1•Zþ“cñn·WcÖ—^ױͯ{vnº¬Š?Gú;>¥×HÌÍ ;Ë趻1ÃXÞXE·U½ÛÚëjvËm¯ù»í¥$Øg5oœöàe6’ïUÍÕ䈇ìh?ÊoÒZØfü7Ó_¨ëðì–šß´¸¬©çý£õ| ™.êö¸9ÙÕ´µÌØ7oôÚ^_ù¿¢]WHÃÊéÞ¥MÈÙM¦ÊØç—ÔøüëÙº¼zgþÿ]@Fš¤@îM:lµ´Øñé87G¸ßú …®h‰]ÚÛ»Ûô”¨‘[}¤5¡®[mÔB#m€;¾–âHŸÞŸA2ÓOÿÐØeùms 9>¬$6Æ‚þÅ»OM•·é½¿A[}dvy²%ÓUm–þ{}˜¬ÿ³›XµÇÖ$¹Î/¬ŠÉçÝîm›ìPê é9î©âÛN-¢‘¡#ÙgcÝùߺ©‰ 4~QR§ƒÅÏÊëŸY}{2/Úí}ï 6ºkþlƒký*kck¯ü%«wë¯ÕþƒÓ:^5˜[}ksÈ%ÌÉe–Q“鵕ÑO¿ô‹àíX_TrÛÒ:î.sîkqÜÈsÃEq{-¨Ã·Væî]?׎°léýùÍê7é•}•–Vêz2ú›üåÖ} œ®šÿOüã÷ ©¯Â8ŽöñظؖÛ.$À&8;{(.‹ê†ÙýG3 ‡Vës±_fÌ’çT÷±Í5`õ=Žµïÿ·-ŠýŽÆk´5ퟎÕÐýWêé6ÝKÞÛ|6½©çOå¹·)Æ›07úÎAÉè2¼†MÌ·'}–<Ûpu"¼m¾óo§S,²ÖUé»Ñ³Óõë?Õ|ºè§©â\FìÜ>Ïke¶ëcÿ™u>æ:ê]gÑú~‡¥þYu=3êýùY~f}™§dÒw;ôcô;%´Wÿj>õú7þ’Ï´.[Ö¿ §i>>”ÿ'`NœDNŸbé|Ö÷]S¡çt,7de:«q0™KâÐíïs^û}ORÇUëc?ÞÇú4ƒ¦°zhÆ¢¬<zìn-98ïê^ö nÛU[7V÷Ué×ûÿáU~§˜ü®Ôí,-f54`V]ùÏ~U™×Ÿëm¶¯ü…ͪý3©çÙÑ™ŒÇX[X, ÁsNæ>\ãí©þsr¦xŒ²\¸¢$îþ®2¯ù̸èKmuüßJ=Y®Äk®±·qM&’ÆäTMôîyýb·í¿Ù²¿F¶,«ðÀé½ËÆÚn~ÛŒO¥Hõ[‹¾ÂßS"Æú[ýŸ£V3l£/¥¬7}ŸpƳkE[žo©›?šôØÊýûóââú÷[~G]fV)sqñHƱÚFÇ}¢ë=¿ðÎÛ¿þ Xå ȸŒ@óFzÒ©U}/>ú1rÅÃÀ)Ì›¶ÆYì67ôW}6ÿ!G*є̧½Óu¦ŒË(pÜk†O®Æ·gÒ±¯üÿJßÌY)×u<çîõ.ºÍÍ:û·ä¹jýVêdWWX`n'¼7!íÒšßéZvû÷WßÑ]`:‰pÈ6èýuêÂìŒ,jìµØuÙÙÜðëZÚ»iÛ^=3»fïðŠ?Púë:U½A¶:¶å =Lg[%¶;}˜²Ò×z—ûEŸñý"—SÅè½S¥Y×qÞê›[N5,x.psØÖdjïO'7w³êõ¾•É2 Æš÷5´™²}ÆaÛ!21¯¾ôfeÃ~’c®IO^·+$âT]}zÁÆ7h]ú-ÁþŸé½7ú›Wm_YÆÃúµC¬u‡?©°‡ÜÿI£ôÖ×ù¿fôÜÖÓÿu~§é½Eä¸6º»Zö»c†¡Üí#ÜÉÚ½OêwÖŸÔÔlÈÄ;±ë'9¢ÏÔqÚÊÙŠïðûÏ«{?Â]“ÿm¾…“KŒ¿Wu2?dxxZ8Zo¥ÖWuM±€–µÀíx`ÓgzìýÏrßÇÉ£.¦ÝAý –¾FÒ#ÔáÏsWžg[XËcªo§KÈ5Ö$íiu—Šÿ;vÏjé¾fX×e³kì§ÑìgÒ/ÏMü÷ÜÏ ÏßE–È ¥Øæx¨›·ÿÑØkØZI2ÐÇö=«ë?YôÁéØÎsr/¥¿hy ºÜL1Ýeíoç5Jé³Öª=O?¥ÿGwæþæÕÀ}cùÇ—¢)‰™þn¿æ÷{½?몘¸x½TÝËÅÁé߯“Ÿ^U½®pmåÇÙ¸†Ã™ïÚÍ›~“W_õÛ;£õ~™W£NV=ØC6€ú©·óžü{–Ïìz«’oÐtÄzµý/£ßùˆ÷úëÅßÿ2}³?µ³ÕÙ¶vûþË¿ó¶Iõ¿Gý#Ðý2´xzUÓZH$D‘Ät~‘ÿóëců§]FÀßpk‡ýxÜKs«h.f¶°Ï-×Ýë±TgôÖñ_xQÿÍþvÏÜܬëédÿžcŽó‰ñ»ÑÕ«©÷ô±Ÿ½ØXÕ²»És½l—{ÓÛôÿà™éªÝUø·u\öbí¶mk ck5ie©¿›^öûzcÒí>Œø~wç$ÍÞµñº=*ÿ›Û·ó¿{ß·ÿR¡;÷ •ñQ±ú;ÿÒ]¯ Ð|Ûþ“Ÿö«êmxÆçýÁŽºãé’é5ý?kX½‹êñé}êO~{Ûv[mȱÎüûŸúW·ÑöÖÖ3þ.•ãþ–ÉŽ*ø}ø/Rê_gÿ˜½#í_eÙö†ú´ýoKvË£Ñý›úoKý7ÚWô=_ø4ÃÃGÏZî¨ñq ߣ¡×Ós:ŸA»=ƒ#¦f2ꨂëm4ú7µŽôÿ@ÿÑW[ÿ?Õõ?›÷¯9êõbŽ¥—V){h§!ì«|µáqcØæŸøFþzï¿ÆTþ×è_Ol»ˆô§ÔÇúŸêï¿ü"ó«çí?J~Ñw1»é÷þWúDÜ_Îún¸GøÜLÙ?™UÅÄtþ¯òÿ˜ÑÈsCÚóíôçÌ™.çúʹÌÂô›~A»ÿꞟ/éÙýFqÏÒ?IW?Ì~›¿êX§•Û]í:ìÛºx¹‘[ufËIÛ¸l¶¦5öƒ«Ô£nåÎdšVg¢©ÖX*:’æ¯Tj?£Ùüìog?Ìsoó_þ·ª/Ÿ±[áëwŽdÿ5ùßñ¿˜£¯Q6vÛôQ áÐúäoô¿ºªÜ [õ_¨ÙÑïǶêf.V-•¸VFíö»½¯-öúmbã‡þ¨ü‹¯³Šøüߣô~æßSÅ¥Ïêv=·áÖçmÄ<hHhK_5ÕýI³}¶z‡GQïùZÐ×7Ÿ¡½qcúf/<;Ž{.‹ê«¶Ý¾´úVDz{ãu_ÍïöìÿK»ßüâƒ?µ>š´¶H|ÁÿÙÿíÞPhotoshop 3.08BIM%8BIM/JÿÿHHÐ@dÀ°'llun×8BIMíHH8BIM&?€8BIM x8BIM8BIMó 8BIM 8BIM' 8BIMõH/fflff/ff¡™š2Z5-8BIMøpÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿèÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿè8BIM8BIM8BIM08BIM-8BIM@@8BIM8BIMI Ö Untitled-1Ö nullboundsObjcRct1Top longLeftlongBtomlong RghtlongÖslicesVlLsObjcslicesliceIDlonggroupIDlongoriginenumESliceOrigin autoGeneratedTypeenum ESliceTypeImg boundsObjcRct1Top longLeftlongBtomlong RghtlongÖurlTEXTnullTEXTMsgeTEXTaltTagTEXTcellTextIsHTMLboolcellTextTEXT horzAlignenumESliceHorzAligndefault vertAlignenumESliceVertAligndefaultbgColorTypeenumESliceBGColorTypeNone topOutsetlong leftOutsetlongbottomOutsetlongrightOutsetlong8BIM(?ð8BIM8BIM” +àP xÿØÿàJFIFHHÿíAdobe_CMÿîAdobed€ÿÛ„ ÿÀ+ "ÿÝ ÿÄ? 3!1AQa"q2‘¡±B#$RÁb34r‚ÑC%’Sðáñcs5¢²ƒ&D“TdE£t6ÒUâeò³„ÃÓuãóF'”¤…´•ÄÔäô¥µÅÕåõVfv†–¦¶ÆÖæö7GWgw‡—§·Ç×ç÷5!1AQaq"2‘¡±B#ÁRÑð3$bár‚’CScs4ñ%¢²ƒ&5ÂÒD“T£dEU6teâò³„ÃÓuãóF”¤…´•ÄÔäô¥µÅÕåõVfv†–¦¶ÆÖæö'7GWgw‡—§·ÇÿÚ?ÊoÕÞ°^ €a¶>¦Œ±ß÷ÔFýZêÏqÚÊìv€·{xìàáù‹ªÆÇ7[E,k=[ cÙ$†ºÝ³ýJÖƒúF]uÙcv1¬a/s¶8éîq~áÿ~U‘Ô«pðÇBǺ¦=˜½Vú.o§m>×°þk‡æ¨0°·Ê~Œr~—µo}yé·¬fÌf¶×åc×{«dHÚÏJÛ!¤·gè4ãe.÷·ná-âîæv»û*hë|òù›aÍk¤KgXCÄnëعÁ¢u]ùüûSŒ†8¶±¡$4Èît•§Ð1.¯¨YŒôZí¯sijw¨k¨¿¥g»Õúýž¢= ¢.A>WIÍ¡þ¥”œÌbgsZCˆ˜-{gô^àªUÐ_‹Mw]‹Huµmõvmmý)eo}5»ôŸ¾»ŒÌ^›õzÜ‹Y™Ó ½”Uê6ÆÝc†Ìv6¼íù>Ýk¶Yú/ç=K=J×-Òq²nÇ·2îcì™ ª_sXÆï¯~ö;Òö;zhâÔŽŒ²kt~µ}Y£§ôÜ{1jÍõé±µ]n[Úíõ¿#~8cŸüÆÍ–¬—Cœ×I‡Äêþêéþ¿dõ,z0:xõëé×T.smq±Û›S+ÈŸµµú5ÛUO}žû=[žû–Õ¾œü̯LZ1i6mȽà¸5°Øk)öî³wç»ù´<6VH:}'.ì‹šç;qnÖ´aãvÈ>ýîÜ»«®¹õúnªÂÚÛ\櫓¯e>›¿GOÐwæ³þ s¹?Qs°rVæêA—:ç ÖRïgÚéì¦ßOÕoæzÕÚ·c)¿Qr¬i»Ê1M-¶ßlÛ¸ þϵﻦÌûgØš`dA®‹âc›ÐÚùÇTeæåg‡ÐËžcCZ>—æ1›}Ÿ˜ÅRª®tÖÀ_k†Ö°N³ôyZtl¼‚Â×c¸9ÛM6XXö’}1»c}»Ÿüß»ÓWú%UfŠ3hs¡®9°÷?éz›v4ú;w{íÛìÿH¤7ÃñK³[¦õ“m®Ãsê£vŒ-iœË\í¯þ¯Ó]Fú›Óº¯KÕmyŽ’ÖÏL8ôÝTz›?—½7X¥9”1•Zþ“cñn·WcÖ—^ױͯ{vnº¬Š?Gú;>¥×HÌÍ ;Ë趻1ÃXÞXE·U½ÛÚëjvËm¯ù»í¥$Øg5oœöàe6’ïUÍÕ䈇ìh?ÊoÒZØfü7Ó_¨ëðì–šß´¸¬©çý£õ| ™.êö¸9ÙÕ´µÌØ7oôÚ^_ù¿¢]WHÃÊéÞ¥MÈÙM¦ÊØç—ÔøüëÙº¼zgþÿ]@Fš¤@îM:lµ´Øñé87G¸ßú …®h‰]ÚÛ»Ûô”¨‘[}¤5¡®[mÔB#m€;¾–âHŸÞŸA2ÓOÿÐØeùms 9>¬$6Æ‚þÅ»OM•·é½¿A[}dvy²%ÓUm–þ{}˜¬ÿ³›XµÇÖ$¹Î/¬ŠÉçÝîm›ìPê é9î©âÛN-¢‘¡#ÙgcÝùߺ©‰ 4~QR§ƒÅÏÊëŸY}{2/Úí}ï 6ºkþlƒký*kck¯ü%«wë¯ÕþƒÓ:^5˜[}ksÈ%ÌÉe–Q“鵕ÑO¿ô‹àíX_TrÛÒ:î.sîkqÜÈsÃEq{-¨Ã·Væî]?׎°léýùÍê7é•}•–Vêz2ú›üåÖ} œ®šÿOüã÷ ©¯Â8ŽöñظؖÛ.$À&8;{(.‹ê†ÙýG3 ‡Vës±_fÌ’çT÷±Í5`õ=Žµïÿ·-ŠýŽÆk´5ퟎÕÐýWêé6ÝKÞÛ|6½©çOå¹·)Æ›07úÎAÉè2¼†MÌ·'}–<Ûpu"¼m¾óo§S,²ÖUé»Ñ³Óõë?Õ|ºè§©â\FìÜ>Ïke¶ëcÿ™u>æ:ê]gÑú~‡¥þYu=3êýùY~f}™§dÒw;ôcô;%´Wÿj>õú7þ’Ï´.[Ö¿ §i>>”ÿ'`NœDNŸbé|Ö÷]S¡çt,7de:«q0™KâÐíïs^û}ORÇUëc?ÞÇú4ƒ¦°zhÆ¢¬<zìn-98ïê^ö nÛU[7V÷Ué×ûÿáU~§˜ü®Ôí,-f54`V]ùÏ~U™×Ÿëm¶¯ü…ͪý3©çÙÑ™ŒÇX[X, ÁsNæ>\ãí©þsr¦xŒ²\¸¢$îþ®2¯ù̸èKmuüßJ=Y®Äk®±·qM&’ÆäTMôîyýb·í¿Ù²¿F¶,«ðÀé½ËÆÚn~ÛŒO¥Hõ[‹¾ÂßS"Æú[ýŸ£V3l£/¥¬7}ŸpƳkE[žo©›?šôØÊýûóââú÷[~G]fV)sqñHƱÚFÇ}¢ë=¿ðÎÛ¿þ Xå ȸŒ@óFzÒ©U}/>ú1rÅÃÀ)Ì›¶ÆYì67ôW}6ÿ!G*є̧½Óu¦ŒË(pÜk†O®Æ·gÒ±¯üÿJßÌY)×u<çîõ.ºÍÍ:û·ä¹jýVêdWWX`n'¼7!íÒšßéZvû÷WßÑ]`:‰pÈ6èýuêÂìŒ,jìµØuÙÙÜðëZÚ»iÛ^=3»fïðŠ?Púë:U½A¶:¶å =Lg[%¶;}˜²Ò×z—ûEŸñý"—SÅè½S¥Y×qÞê›[N5,x.psØÖdjïO'7w³êõ¾•É2 Æš÷5´™²}ÆaÛ!21¯¾ôfeÃ~’c®IO^·+$âT]}zÁÆ7h]ú-ÁþŸé½7ú›Wm_YÆÃúµC¬u‡?©°‡ÜÿI£ôÖ×ù¿fôÜÖÓÿu~§é½Eä¸6º»Zö»c†¡Üí#ÜÉÚ½OêwÖŸÔÔlÈÄ;±ë'9¢ÏÔqÚÊÙŠïðûÏ«{?Â]“ÿm¾…“KŒ¿Wu2?dxxZ8Zo¥ÖWuM±€–µÀíx`ÓgzìýÏrßÇÉ£.¦ÝAý –¾FÒ#ÔáÏsWžg[XËcªo§KÈ5Ö$íiu—Šÿ;vÏjé¾fX×e³kì§ÑìgÒ/ÏMü÷ÜÏ ÏßE–È ¥Øæx¨›·ÿÑØkØZI2ÐÇö=«ë?YôÁéØÎsr/¥¿hy Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049530 Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 It may be a security issue if that is what is happening. Does the image HAVE to be outside of your server root? Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049539 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Hi again, Yes, its ultimately out of the webfolder due to security. I'll have to check the permissions of the folder and make sure IIS users have read permissions. Do you think they will need something else? Jalz Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049556 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2010 Share Posted April 27, 2010 Is this correct: With the header() statements commented out, you get the contents posted in Reply #17 and with the header() statements in the code you get a broken red-x image? Does that exact same image file work when it is placed inside the document root folder? What does a phpinfo(); statement show for the magic_quotes_runtime setting (I see a few \ in the data that could be escape characters)? Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049572 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 Hi PFMaBiSmAd, The magic_quotes_runtime setting is switched to off. Copied the exact image into my webfolder and changed the filepath so it is 'ajkimage.png'. With the headers commented out, I get the gibberish, with them included in the code I get a red cross. This is in I.E 8. FireFox says the image in http://localhost/folder/testdisplayimage.php cannot be displayed as it contains errors. I get the same results when I try a change the filePath to the image that is outside the webroot. Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049585 Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2010 Share Posted April 27, 2010 Any chance that the .php file has some characters in it after the closing ?> tag? Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049586 Share on other sites More sharing options...
Jalz Posted April 27, 2010 Author Share Posted April 27, 2010 This is my entire php file which I am using to test this feature. It may look a little strange, as it is connecting to a FileMaker database, but the connection etc all work; Just cant get the image to display <?php ini_set("display_errors", "1");error_reporting(E_ALL); require_once('Connections/dbConnect.php'); ?> <?php $MyDetails_find = $OO_Secure->newFindCommand('Members'); $MyDetails_find->AddFindCriterion('MemberID',$_SESSION['memberid']); $MyDetails_result = $MyDetails_find->execute(); if(FileMaker::isError($MyDetails_result)) fmsTrapError($MyDetails_result,"error.php"); $MyDetails_row = current($MyDetails_result->getRecords()); // FMStudio v1.0 - do not remove comment, needed for DreamWeaver support ?> <?php $filePath = $MyDetails_row->getField('ImageURL'); //$filePath = 'ajktest.png'; header('Content-type: image/png'); header('Content-length:' . filesize($filePath)); echo file_get_contents($filePath); ?> Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049588 Share on other sites More sharing options...
de.monkeyz Posted April 27, 2010 Share Posted April 27, 2010 Exiting and entering php like that for no reason could be the reason, change it to this: <?php ini_set("display_errors", "1");error_reporting(E_ALL); require_once('Connections/dbConnect.php'); $MyDetails_find = $OO_Secure->newFindCommand('Members'); $MyDetails_find->AddFindCriterion('MemberID',$_SESSION['memberid']); $MyDetails_result = $MyDetails_find->execute(); if(FileMaker::isError($MyDetails_result)) fmsTrapError($MyDetails_result,"error.php"); $MyDetails_row = current($MyDetails_result->getRecords()); // FMStudio v1.0 - do not remove comment, needed for DreamWeaver support $filePath = $MyDetails_row->getField('ImageURL'); //$filePath = 'ajktest.png'; header('Content-type: image/png'); header('Content-length:' . filesize($filePath)); echo file_get_contents($filePath); Notice I even removed the final ?> which is valid and prevents any accidental output after the php Quote Link to comment https://forums.phpfreaks.com/topic/199929-displaying-images-using-the-readfile-command/#findComment-1049592 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.