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="$uploaddir/$img_id("$img_id"
border="0">';
// display some information
echo "Image uploaded.<br><img src=\"img?f\"><br>".
"URL: $server$uploaddir$myimage_name";
return $img;
?>
example 2:
my first way of trying to display image from database to a browser.
<?php
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files WHERE id_files=$id_files";
$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, "bin_data"
;
$name = @mysql_result($result, 0, "filename"
;
$size = @mysql_result($result, 0, "filesize"
;
$type = @mysql_result($result, 0, "filetype"
;
header("Content-type: $type"
;
header("Content-length: $size"
;
header("Content-Disposition: attachment; filename=$name"
;
header("Content-Description: PHP Generated Data"
;
echo $data;
}
?>
my second way of trying to display image from database to a browser.
<?php
//open the connection
$conn = mysql_connect("localhost", "cyber", "cs7536"
;
//selecting the database
mysql_select_db("binary_files",$conn);
$result = ("SELECT * FROM tbl_Files WHERE id_files=$id_files"
;
$data = mysql_query($result);
$row = mysql_fetch_array($data);
$name = $row['id_files'];
echo "<p>$name</p>";
echo "
header (\"Content-type: image/jpeg\"
;
<div id=\"under\" style=\"left: 225px; top: 132px; position: absolute\"> <img src=\"../FRAME.jpg\" width=\"300\" height=\"375\"> </div>
<div id=\"top\" style=\"left: 261px; top: 166px; position: absolute\"> <img src=\"../$name\" width=\"228\" height=\"308\"> </div>
<BR><BR>
"
?>
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
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="$uploaddir/$img_id("$img_id"

// display some information
echo "Image uploaded.<br><img src=\"img?f\"><br>".
"URL: $server$uploaddir$myimage_name";
return $img;
?>
example 2:
my first way of trying to display image from database to a browser.
<?php
if ($id_files) {
include "open_db.inc";
$sql = "SELECT bin_data, filetype, filename, filesize FROM tbl_Files WHERE id_files=$id_files";
$result = @mysql_query($sql, $db);
$data = @mysql_result($result, 0, "bin_data"

$name = @mysql_result($result, 0, "filename"

$size = @mysql_result($result, 0, "filesize"

$type = @mysql_result($result, 0, "filetype"

header("Content-type: $type"

header("Content-length: $size"

header("Content-Disposition: attachment; filename=$name"

header("Content-Description: PHP Generated Data"

echo $data;
}
?>
my second way of trying to display image from database to a browser.
<?php
//open the connection
$conn = mysql_connect("localhost", "cyber", "cs7536"

//selecting the database
mysql_select_db("binary_files",$conn);
$result = ("SELECT * FROM tbl_Files WHERE id_files=$id_files"

$data = mysql_query($result);
$row = mysql_fetch_array($data);
$name = $row['id_files'];
echo "<p>$name</p>";
echo "
header (\"Content-type: image/jpeg\"

<div id=\"under\" style=\"left: 225px; top: 132px; position: absolute\"> <img src=\"../FRAME.jpg\" width=\"300\" height=\"375\"> </div>
<div id=\"top\" style=\"left: 261px; top: 166px; position: absolute\"> <img src=\"../$name\" width=\"228\" height=\"308\"> </div>
<BR><BR>
"
?>
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