Hello guys! Greetings to everyone!
I have tried the following code but it doesn't display images, it only stores data.
Here's the code in displaying images:
<?php
if ($submit) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$data = addslashes(fread(fopen($form_data, "rb"), filesize($form_data)));
$result=MYSQL_QUERY("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name','$form_data_size','$form_data_type')");
$id= mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";
print "<img src=getdata.php?id=".$id ."/>";
MYSQL_CLOSE();
} else {
?>
<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" 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" size="40">
<p><input type="submit" name="submit" value="submit">
</form>
<?php
}
?>
It stores data in my database(means working, please check if there is conflict. i hope i dont bother any of you) thanks.. :)
Here's code in storing images:
<?php
if($id) {
$link=mysql_connect("localhost","root","1234");
if(!$link) die("Could not connect to MySQL");
$db=mysql_select_db("test",$link);
$query = "select bin_data,filetype from table where id='$id'";
$result = MYSQL_QUERY($query);
$data = MYSQL_RESULT($result,0,"bin_data");
$type = MYSQL_RESULT($result,0,"filetype");
header( "Content-type: $type");
header( "Content-type: image/pjpeg");
echo $data;
}
?>
No errors but none of the images stored in the database display. please help me troubleshooting this. thanks a lot. :)
Below is the list of fields i have created.
CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
)