Originally posted by mdesouza
can u explain the insert bit !!
here is my product table
CREATE TABLE products (
product_id int(4) DEFAULT '0' NOT NULL auto_increment,
category_id int(4) DEFAULT '1' NOT NULL,
product_name varchar(50) DEFAULT '' NOT NULL,
product_description varchar(240),
product_image blob,
PRIMARY KEY (product_id)
unless you are going to restrict the user's to only uploading one type of image, you will need to store what type of image they uploaded so you know how to output it to the browser.
for the example we will use a field called product_imagetype and it will hold values like 'gif', 'jpg'...
once you get the image file contents into a variable thru file_get_contents, you could store it like this:
$query = "INSERT INTO products ('', '5', 'computer', 'p4 3.2ghz', '".addslashes("$imagedata")."'";
and when you pull it out for the image script you can do this:
$pid = $_GET['id'];
$query = "SELECT product_image, product_imagetype FROM products WHERE product_id = '$pid'";
$result = mysql_query($query);
$data = mysql_fetch_array($result);
$image = stripslashes($data[0]);
$type = $data[1];
switch($type) {
case "jpg":
header("Content-Type: image/jpg");
break;
case "gif":
header("Content-Type: image/gif");
break;
case "png":
header("Content-Type: image/png");
break;
//..other types here that you allow
}