I successfully inserted image file to my database having a datatype BLOB here is my code name copy.php which is an action called on an html for uploading file
<?
//Include config file
include('common.php');
//attempt to copy file to directory temp
copy ($file,"temp/test.jpg");
//get filesize of $file
$size = number_format(filesize("temp/test.jpg")) . "bytes";
echo $size . "<br>";
$maxsize = 65536;
echo $maxsize . "<br>";
if ($size>$maxsize){
print "File is too large";
exit;
}
//attemp to connect to MySQL server
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
// If connection failed...
if (!$link) {
// Inform user of error and quit
print "Couldn't connect to database server";
exit;
}
// Attempt to select database
if(!@mysql_select_db($dbName)) {
// Inform user of error and exit
print "# Couldn't select database <br>\n";
exit;
}
// Build Query
$data = addslashes(fread(fopen("temp/test.jpg","r"), filesize("temp/test.jpg")));
if (!data) die ("Cannot open file");
$query = "INSERT INTO imagetable (image)
VALUES('$data')";
echo $query."<br>";
// Execute Query
$result = @($query);
// Close the connection
mysql_close($link);
?>
im trying to retieve it right now with this code
name:image_viwer.php
<?php
//Include config file
include('common.php');
//Attemp to connect to MySQL server
$link = @mysql_connect($dbHost, $dbUser, $dbPass);
if(!$link){
print "Cannnot connect to server";
exit;
}
//Attempt to connect to database
if(!@mysql_select_db("phpforflash")){
print "Cannot connect to database";
}
//Build query
$result = mysql_query("SELECT image from imagetable WHERE imageid=1");
$data = mysql_result($result,0,"image");
echo $data;
//Close link
mysql_close($link);
?>
try to display it on htm code like this
<head>
<title>Image Data Viewer</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<img src="image_viewer.php?id=1">
</body>
------------------------------------------------------------image dont display on browser
.Was it my insertion or retieval???Thanks for any help