i used a code from a website that allows you to display images. however everything works fine from storing the image to the database but it does not display the image.
the following code is the one i have used.
Storing the images:
[PHP]<HTML>
<HEAD><TITLE>St ore binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
if (isset($_REQUES T['submit'])) {
mysql_connect(" localhost","roo t","");
mysql_select_db ("binary_data") ;
$data = addslashes(frea d(fopen($_FILES['form_data']['tmp_name'], "r"), $_FILES['form_data']['size']));
$result= mysql_query("IN SERT INTO binary_data (description,bi n_data,filename ,filesize,filet ype) ".
"VALUES ('".$form_descr iption."','".$d ata."','".$_FIL ES['form_data']['name']."','".$_FIL ES['form_data']['size']."','".$_FIL ES['form_data']['type']."')");
$id= mysql_insert_id ();
print "<p>This file has the following Database ID: <b>$id</b>";
mysql_close();
} else {
?>
<form method="post" action="store.p hp" enctype="multip art/form-data">
File Description:<br >
<input type="text" name="form_desc ription" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_ SIZE" value="1000000" >
<br>File to upload/store in database:<br>
<input type="file" name="form_data ">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>[/PHP]
Getting the image from database :
[PHP]<?php
if($id) {
mysql_connect(" localhost","roo t","");
mysql_select_db ("binary_data") ;
$query = "select bin_data,filety pe from table where id='$id'";
$result = mysql_query($qu ery);
$data = mysql_result($r esult,0,"bin_da ta");
$type = mysql_result($r esult,0,"filety pe");
header( "Content-type: $type");
header( "Content-type: image/pjpeg");
echo $data;
};
?>[/PHP]
displaying the image:
[PHP]<html>
<head>
<title>images retrieved from database</title>
</head>
<body>
<img src="getdata.ph p?id=3">
</body>
</html>[/PHP]
if someone can help i would greatly appreciate it.
thanks
ashraf
the following code is the one i have used.
Storing the images:
[PHP]<HTML>
<HEAD><TITLE>St ore binary data into SQL Database</TITLE></HEAD>
<BODY>
<?php
if (isset($_REQUES T['submit'])) {
mysql_connect(" localhost","roo t","");
mysql_select_db ("binary_data") ;
$data = addslashes(frea d(fopen($_FILES['form_data']['tmp_name'], "r"), $_FILES['form_data']['size']));
$result= mysql_query("IN SERT INTO binary_data (description,bi n_data,filename ,filesize,filet ype) ".
"VALUES ('".$form_descr iption."','".$d ata."','".$_FIL ES['form_data']['name']."','".$_FIL ES['form_data']['size']."','".$_FIL ES['form_data']['type']."')");
$id= mysql_insert_id ();
print "<p>This file has the following Database ID: <b>$id</b>";
mysql_close();
} else {
?>
<form method="post" action="store.p hp" enctype="multip art/form-data">
File Description:<br >
<input type="text" name="form_desc ription" size="40">
<INPUT TYPE="hidden" name="MAX_FILE_ SIZE" value="1000000" >
<br>File to upload/store in database:<br>
<input type="file" name="form_data ">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>[/PHP]
Getting the image from database :
[PHP]<?php
if($id) {
mysql_connect(" localhost","roo t","");
mysql_select_db ("binary_data") ;
$query = "select bin_data,filety pe from table where id='$id'";
$result = mysql_query($qu ery);
$data = mysql_result($r esult,0,"bin_da ta");
$type = mysql_result($r esult,0,"filety pe");
header( "Content-type: $type");
header( "Content-type: image/pjpeg");
echo $data;
};
?>[/PHP]
displaying the image:
[PHP]<html>
<head>
<title>images retrieved from database</title>
</head>
<body>
<img src="getdata.ph p?id=3">
</body>
</html>[/PHP]
if someone can help i would greatly appreciate it.
thanks
ashraf
Comment