Moron Posted November 21, 2006 Share Posted November 21, 2006 I'm trying to display employee photos which are stored in the database as binary.As a test, I can put the following code sample (from php.net) as the very [b]first[/b] thing on the page...[code]<?php$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';$data = base64_decode($data);$im = imagecreatefromstring($data);if ($im !== false) { imagejpeg($im);}else { echo 'An error occurred.';}?>[/code]...and I get:[img]http://mywebpages.comcast.net/techie4/phprules.jpg[/img]So the GD library is working. ...but I get [b]nothing[/b] else on the page.If I put the above code anywhere except at the very top of the page, then I just get the ASCII garbage as written.Anyone know why I can't just plug it where I want into the page? I've already looked at the header issue and that's not the problem. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 Yes, it is a header problem. You need to put the code either in a seperate script or in a section of your main script that exits right after sending the data. The script would be invoked via the HTML <img> tag. In the script, you should issue [code]<?phpheader('Content-type: image/jpeg');?>[/code]before sending the image data.Ken Quote Link to comment Share on other sites More sharing options...
Moron Posted November 21, 2006 Author Share Posted November 21, 2006 [quote author=kenrbnsn link=topic=115765.msg471453#msg471453 date=1164128008]Yes, it is a header problem. You need to put the code either in a seperate script or in a section of your main script that exits right after sending the data. The script would be invoked via the HTML <img> tag. In the script, you should issue [code]<?phpheader('Content-type: image/jpeg');?>[/code]before sending the image data.Ken[/quote]Thanks a ton, Ken! One question: when you say a "seperate script," does that mean that I could just have it in an .inc file and call that file? Quote Link to comment Share on other sites More sharing options...
SharkBait Posted November 21, 2006 Share Posted November 21, 2006 Yup. Quote Link to comment Share on other sites More sharing options...
Moron Posted November 21, 2006 Author Share Posted November 21, 2006 No go. I plugged that sample code into a file called [b]showpic.inc[/b]On the page, I tried:[code]<?phpinclude('showpic.inc');?>[/code]It works [b]only[/b] when called at the top of the page. Anywhere else and I get the ASCII trash as is. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 Please post the code of "showpic.inc" and how you are invoking it.Ken Quote Link to comment Share on other sites More sharing options...
taith Posted November 21, 2006 Share Posted November 21, 2006 <img src="showpic.php"> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 And what's in "showpic.php"? Quote Link to comment Share on other sites More sharing options...
Moron Posted November 21, 2006 Author Share Posted November 21, 2006 [quote author=kenrbnsn link=topic=115765.msg471495#msg471495 date=1164132680]Please post the code of "showpic.inc" and how you are invoking it.Ken[/quote]Here you go. It's showpic.inc. It's just the sample from php.net:[code]<?php$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';$data = base64_decode($data);$im = imagecreatefromstring($data);if ($im !== false) { imagejpeg($im);}else { echo 'An error occurred.';}?>[/code]I'm invoking it by:[code]<?phpinclude('showpic.inc');?>[/code]You may notice that I don't have the "header" line in the code. That's because I have...[code]header('Content-Type: image/jpeg');[/code]...at the top of my page. If I put it in showpic.inc also, it conflicts and throws an error. Quote Link to comment Share on other sites More sharing options...
SharkBait Posted November 21, 2006 Share Posted November 21, 2006 Put the header('Content-Type: image/jpeg'); in the script of the showpic.inc file before you use the imagejpg() function Quote Link to comment Share on other sites More sharing options...
taith Posted November 21, 2006 Share Posted November 21, 2006 this is how you export a php made image into html, it has to be put out as a html string.[code]<img src="showpic.php">[/code]then in your showpic.php[code]<?header('Content-Type: image/jpeg');$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';$data = base64_decode($data);$im = imagecreatefromstring($data);if($im !== false) imagejpeg($im);else echo 'An error occurred.';?>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 21, 2006 Share Posted November 21, 2006 Try this simple script. Everything in one script, no includes:[code]<?phpif (isset($_GET['p'])) { $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='; $data1 = base64_decode($data); $im = imagecreatefromstring($data1); if ($im !== false) { header('Content-Type: image/jpg'); imagejpeg($im); } exit();}for($i=0;$i<10;$i++) echo '<img src="' . $_SERVER['PHP_SELF'] . '?p=1"> ... ' . $i .' ... <br>';?>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Moron Posted November 21, 2006 Author Share Posted November 21, 2006 [quote author=kenrbnsn link=topic=115765.msg471544#msg471544 date=1164136118]Try this simple script. Everything in one script, no includes:[code]<?phpif (isset($_GET['p'])) { $data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg=='; $data1 = base64_decode($data); $im = imagecreatefromstring($data1); if ($im !== false) { header('Content-Type: image/jpg'); imagejpeg($im); } exit();}for($i=0;$i<10;$i++) echo '<img src="' . $_SERVER['PHP_SELF'] . '?p=1"> ... ' . $i .' ... <br>';?>[/code]Ken[/quote]This works if it's the absolute first thing on the page. Otherwise, it just shows:...0......1...etc....with X's and no image. Quote Link to comment Share on other sites More sharing options...
Moron Posted November 21, 2006 Author Share Posted November 21, 2006 [quote author=taith link=topic=115765.msg471522#msg471522 date=1164134217]this is how you export a php made image into html, it has to be put out as a html string.[code]<img src="showpic.php">[/code]then in your showpic.php[code]<?header('Content-Type: image/jpeg');$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl' . 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr' . 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r' . '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';$data = base64_decode($data);$im = imagecreatefromstring($data);if($im !== false) imagejpeg($im);else echo 'An error occurred.';?>[/code][/quote]Thanks, but this just gives me the X and no picture. :-[EDIT! - Typo on my part! I put showpic.[b]inc[/b], not showpic.[b]php[/b]. IT SHOWS!Thanks!Now I need to make it point to my database pics! Quote Link to comment Share on other sites More sharing options...
taith Posted November 21, 2006 Share Posted November 21, 2006 sorry... i'm not going to be much more help here... i only ever worked with simple php images (stick men(dont laugh ;D))...however you no longer need the whole[code]<?if($im !== false) else echo 'An error occurred.';?>[/code]as pictures dont output text the same way :-) Quote Link to comment Share on other sites More sharing options...
Moron Posted November 21, 2006 Author Share Posted November 21, 2006 Okay, I'm thiiiissss close now. Here are the contents of the showpic.php file:[code]<?phpheader('Content-Type: image/jpeg');$data = 'iVBORw0KGgoAAAANSUhEUgAAABwAAAASCAMAAAB/2U7WAAAABl'. 'BMVEUAAAD///+l2Z/dAAAASUlEQVR4XqWQUQoAIAxC2/0vXZDr'. 'EX4IJTRkb7lobNUStXsB0jIXIAMSsQnWlsV+wULF4Avk9fLq2r'. '8a5HSE35Q3eO2XP1A1wQkZSgETvDtKdQAAAABJRU5ErkJggg==';$data = base64_decode($data);$im = imagecreatefromstring($data);if($im !== false) imagejpeg($im);else echo 'An error occurred.';?><?php session_start();$_SESSION['empcode'] = $empcode;$_SESSION['middle'] = $middle;$_SESSION['firstname'] = $firstname;$_SESSION['lastname'] = $lastname;$_SESSION['leavehours'] = $leavehours;?><?php//CONNECTION STATEMENT. Can also be plugged into an .inc file, then just refer to the .inc file.$conn = mssql_connect("ORSERVI","USERNAME","PASSWORD") or die ("Could Not Connect to Database.<br>Please Notify Computer Services.");mssql_select_db('PerMaster',$conn);?><?php$RESULTDS=mssql_query("SELECT DISTINCT LH.[Employee Number], M2.[HRYRAT], M2.[EMPNO], M2.[MANLAP], M2.[PAYCTR], M2.[MANLAC], M2.[MANLTC], M2.[MSKLAB], M2.[MSKLTC], M2.[NAMEMI], M2.[NAMEL], M2.[NAMEF], EH.[DATE], EH.[ENETPA], LH.[LOCC], EH.[EGRSER], EH.[EREGHR], EH.[EDEDUC], EH.[EROTHR], EH.[EFWHD], EH.[EPEDAT], EH.[ESSDED], EH.[EHOSPD], EH.[ELIFED], EH.[ECRUD], M2.[POSITN], M2.[MCTDWH], M2.[MHDATE], M2.[MCTDCS], M2.[MO3TOT], M2.[MCTDLD], M2.[MCTDGE], M2.[MALPPP], M2.[MSLPPP], M2.[MWHSTA], M2.[MWHALL], M2.[MWHADD], EH.[EGARND], EP.[EMPNO], DP.[EMPNO], EI.[DDEPTN], EI.[NEWOCC], EI.[HRYRAT], EI.[MEMPAD], EI.[MEMPCS], EI.[MEMPZI], view_EmployeeInfo.[EmpPicture]FROM LEAVHST LH JOIN MASTERL2 M2 ON LH.[Employee Number]=M2.EMPNO JOIN EARNHIST EHON EH.[EEMPNO]=M2.EMPNO JOIN EMPPICTURE EPON EP.[EMPNO]=EH.EEMPNO JOIN Departments DPON DP.[EMPNO]=EP.EMPNO JOIN View_EmployeeInfo EION EI.[EMPNO]=M2.EMPNOWHERE M2.[EMPNO] = '".$_POST['employeenumber']."' and M2.[MSSNO] = '".$_POST['password']."' ORDER BY EH.[DATE] desc"); $RESULT=mssql_fetch_assoc($RESULTDS) or die("<CENTER><img src=\"http://orserva/images/invalidnumber.gif\"></CENTER><BR><CENTER><table width=60 //border=0><tr><td><font size=\"3\" color=\"#000000\" face=\"arial\">Need help? Here is an example entry:</font></td></tr><tr><td align=center><img //src=\"http://orserva/images/leaveexample.gif\"></td></tr><tr><td><font size=\"3\" color=\"#000000\" //face=\"arial\">Enter your Employee Number<BR>Enter your password (Social Security Number)<BR>Click Submit<BR><BR>If you're still having difficulty, click here to </font><font size=\"3\" color=\"#ff0000\" //face=\"arial\"><BR><a href=\"mailto:HelpDesk@cortn.org? subject=Problem with the Pay Stubs On Demand //System\"><b>E-mail the HelpDesk</b></a></font></td></tr></table></CENTER>");?>[/code]This works [b]only[/b] if the script at the top is left at the top. So....how do I use $RESULT[EmpPicture] as my variable to get the binary picture from?In the other page, using [i]<img src=......> does indeed now let me put the picture where I want it. Quote Link to comment 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.