Hi frnds,
I want to store images in database and retrieve. I can successfully stored. But i dont know how retrieve it. If any one know pls help me. I paste my code here.
fimg.php
<body>
<form enctype="multipart/form-data" action="insert.php" method="post" name="changer">
<input name="MAX_FILE_SIZE" value="102400" type="hidden">
<input name="image" accept="image/jpeg" type="file">
<input value="Submit" type="submit">
</form>
</body>
insert.php
<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "simg";
$link = mysql_connect($host, $username, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db ($database);
if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) {
$tmpName = $_FILES['image']['tmp_name'];
$fp = fopen($tmpName, 'r');
$data = fread($fp, filesize($tmpName));
$data = addslashes($data);
fclose($fp);
$query = "INSERT INTO img";
$query .= "(image) VALUES ('$data')";
$results = mysql_query($query, $link);
print "Thank you, your file has been uploaded.";
}
else {
print "No image selected/uploaded";
}
mysql_close($link);
?>
seimg.php
<form action="seimg.php">
Enter image id:<input type="text" name="field" />
<input type="submit" name="submit" value="show" />
<?php
$username = "root";
$password = "";
$host = "localhost";
$database = "simg";
@mysql_connect($host, $username, $password) or die("Can not connect to database: ".mysql_error());
@mysql_select_db($database) or die("Can not select the database: ".mysql_error());
$b =$_REQUEST['field'];
$query = mysql_query("SELECT * FROM img WHERE id='$b'");
$row = mysql_fetch_array($query);
$content = $row['image'];
?>