Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

no GD2 image with db variable

Status
Not open for further replies.

torodre

Technical User
Nov 8, 2008
7
0
0
US
result no GD2 image with db variable
Question: How to get printed image instead of file name? The $im = imagecreatefromstring($data); shows empty?

I have gotten database GD2 images to show in browser but without much additional php coding added. Here I make idpic = 135. Or an other number in the range of idpic 1 - 183 pictures in database, this works. What I want to do is use $idpic generated from Example #2|#3 from a regular expression match. I get the idpic # using the WHERE idpic = $idpic in search query. I have and am using this match to fetch images in a file directory. But, when I try and use $data = $rowpic["img"]; in examples #2 and #3 no image. browser print out examples below...

THIS WORKS: #1st Example works
[***********
<?php
header('Content-Type: image/jpeg');
$db = 'mep_db';
$host = 'localhost';
$username = 'root';
$password = 'vahamaki';
$idpic = 135; // is assigned here
mysql_connect($host,$username,$password) or die("Unable to connect to SQL server");
@mysql_select_db($db) or die("Unable to select database");
$result=mysql_query("SELECT * FROM pic WHERE idpic = $idpic") or die("Can't Perform Query");
While($row=mysql_fetch_array($result))
{
$data = $row["img"];
$im = imagecreatefromstring($data);
imagejpeg($im);
imagedestroy($im);
}
echo $row["idpic"]."<BR> idpic CK"; // THIS DOES NOT PRINT OUT IN BROWSERS
echo "<IMG SRC=\"printIMG.php?idpic=$row->idpic\">"; //THIS DOES NOT PRINT OUT IN BROWSERS
?>
] *******************

Example #2....... no work

[ ********
<?php
header('Content-Type: image/jpeg');

........expression match code


$cxn = mysqli_connect($host,$user,$password,$db)
or die ("Couldn't connect to server");
$query = "SELECT * FROM pic WHERE caption = '$regs[0]'";
$resultP = mysqli_query($cxn,$query)
or die("Couldn't execute select query...to get img with caption");
$rowpic = mysqli_fetch_array($resultP);
$idpic = $rowpic["idpic"];
echo $idpic." this is idpic number this works.<br>";
$data = $rowpic ["img"];
$im = imagecreatefromstring($data);
imagejpeg($im);
imagedestroy($im);
?>
] *******

?? Question: result - no image with header at top after <?php

?? echo $idpic; does not print

( this shows in browsers) .......

from IE ver:7.0.5730.13

<br>Match: D044DG<br>illus assigned regs value here <BR>D044DG is illustration caption <BR> illustration regs[0] match

here. D044DG <br> 50Can't Perform Query

FOXFIRE ver: 2.0.0.20

with header() at just before gd2 code:

Example #3 no work

[ ********
......expression match code

$rowpic = mysqli_fetch_array($resultP);
$idpic = $rowpic["idpic"];
echo $idpic." this is idpic number this works.<br>";
$data = $rowpic ["img"];
header('Content-Type: image/jpeg');
$im = imagecreatefromstring($data);
imagejpeg($im);
imagedestroy($im);
?>
] **********

IE browser Prints this
....
Match: D044DG
illus assigned regs value here
D044DG is illustration caption
illustration regs[0] match here. D044DG
50 this is idpic number this works.
Warning: Cannot modify header information - headers already sent by (output started at C:\webs\1219_blob\pdb_img.php:18) in

C:\webs\1219_blob\pdb_img.php on line 37
ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality ÿÛC  

 $.' ",#(7),01444'9=82<.342ÿÛC  2!!...........

there is much more image code ...


FOXFIRE Prints this
....

Match: D044DG
illus assigned regs value here
D044DG is illustration caption
illustration regs[0] match here. D044DG
50
Warning: Cannot modify header information - headers already sent by (output started at C:\webs\1219_blob\pdb_img.php:18) in

C:\webs\1219_blob\pdb_img.php on line 37
ÿØÿà?JFIF??????ÿþ?>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default quality

ÿÛ?C?    $.' ",#(7),01444'9=82<.342ÿÛ?C 

2!!22222222222222222222222222222222222222222222222222ÿÀ??‹F"?ÿÄ???

????????

ÿÄ?µ???}?!1AQa"q2?‘¡#B±ÁRÑð$3br‚

%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyzƒ„…†‡ˆ‰Š’“”•–—˜™š¢£¤¥¦§¨©ª²³´µ¶·¸¹ºÂÃÄÅÆÇÈÉÊ

ÒÓÔÕÖ×ØÙÚáâãäåæçèéêñòóôõö÷øùúÿÄ????????

ÿÄ?µ??w?!1AQaq"2?B‘¡±Á #3RðbrÑ

..... there is much more image code ...

Thank you
 
I resolved the problem:

By commenting out all print and echo statements the image printed out in the browser. The header() is located as in example #3.
It helps to even formulate a question for someone else to read.
Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top