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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

regarding displaying an image 2 ways

Status
Not open for further replies.

cs7536

Programmer
Joined
Apr 20, 2003
Messages
130
Location
US
Hello I am working on php as it is a goal of mine to guru at it one day. I have written 2 scripts that seem to work as I wanted.

script 1: uploads an image to a directory on the system and the name of the image in a table in my dtabase.

script 2: uploads an image and image info into my mysql database.

The problem I am having is as followed:

On both scripts I can not get the image to display on the browser. I have attached both scripts in associated order.


example 1:

$db = mysql_connect("localhost", "cyber","cs7536");
mysql_select_db("erotic",$db);

// retrieve image info from database
$result = mysql_query("SELECT * FROM images2 ".
"WHERE img_id='$img_file");

// check that an entry is found
if (mysql_num_rows($result)!=1) {
return false;
}

// get this row
$img_info = mysql_fetch_array($result);
}

// create and return the img-tag
$img = '<img src=&quot;$uploaddir/$img_id(&quot;$img_id&quot;) border=&quot;0&quot;>';

// display some information
echo &quot;Image uploaded.<br><img src=\&quot;img?f\&quot;><br>&quot;.
&quot;URL: $server$uploaddir$myimage_name&quot;;


return $img;

?>


example 2:

my first way of trying to display image from database to a browser.

<?php
if ($id_files) {
include &quot;open_db.inc&quot;;
$sql = &quot;SELECT bin_data, filetype, filename, filesize FROM tbl_Files WHERE id_files=$id_files&quot;;

$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, &quot;bin_data&quot;);
$name = @mysql_result($result, 0, &quot;filename&quot;);
$size = @mysql_result($result, 0, &quot;filesize&quot;);
$type = @mysql_result($result, 0, &quot;filetype&quot;);

header(&quot;Content-type: $type&quot;);
header(&quot;Content-length: $size&quot;);
header(&quot;Content-Disposition: attachment; filename=$name&quot;);
header(&quot;Content-Description: PHP Generated Data&quot;);
echo $data;
}
?>

my second way of trying to display image from database to a browser.

<?php

//open the connection
$conn = mysql_connect(&quot;localhost&quot;, &quot;cyber&quot;, &quot;cs7536&quot;);

//selecting the database
mysql_select_db(&quot;binary_files&quot;,$conn);

$result = (&quot;SELECT * FROM tbl_Files WHERE id_files=$id_files&quot;);
$data = mysql_query($result);
$row = mysql_fetch_array($data);
$name = $row['id_files'];
echo &quot;<p>$name</p>&quot;;



echo &quot;
header (\&quot;Content-type: image/jpeg\&quot;);
<div id=\&quot;under\&quot; style=\&quot;left: 225px; top: 132px; position: absolute\&quot;> <img src=\&quot;../FRAME.jpg\&quot; width=\&quot;300\&quot; height=\&quot;375\&quot;> </div>
<div id=\&quot;top\&quot; style=\&quot;left: 261px; top: 166px; position: absolute\&quot;> <img src=\&quot;../$name\&quot; width=\&quot;228\&quot; height=\&quot;308\&quot;> </div>
<BR><BR>
&quot;

?>

I am sure you can see I am on the right track but unsure can someone please look at my code and point out what I am doing wrong. please help with solution.

THanks
Max
 
what is the image source displayed in the first method (right click on the page and select 'view source' and check whether the path is as u want it).

Known is handfull, Unknown is worldfull
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top