Jump to content

RE: Blob upload in an Update query


cdoggg94

Recommended Posts

So im not really sure if this is possible but this is what I am trying to do..

 

I have a table that has a list of products...There is a spot for an image for each of these products.

 

What I want to do is give a user the option to add an image to an existing product.

 

I have one spot for image_name, ie: this_picture.jpg

and

and BLOB field for the image file called: image

 

 

this is my code..

 


mysql_connect("locahost","root","") or die(mysql_error());
mysql_select_db("my_db") or die(mysql_error());

$picture = $_FILES['image']['tmp_name'];

if(!isset($picture))
echo "";
	else
	{
	$image = addslashes(file_get_contents($_FILES['image']['tmp_name']));	
	$image_name = addslashes($_FILES['image']['name']);
	$image_size = getimagesize($_FILES['image']['tmp_name']);

	if($image_size==FALSE)
		echo "This is not an Image";
	else{
			if(!$insert = mysql_query ("UPDATE `Sheet1` SET `image_name` = '".$image_name."', `image`='".$image."' WHERE  pro_id ='".$id."';"))
				echo "Problem Uploading Image.";
			else{
				$lastid = mysql_insert_id();
				echo "Image Uploaded!<p />".$text."<p /><p /> Your Image:<p /><img src=get.php?id=$lastid>";
				}
		}

	}

 

 

The get.php page basically just displays the image and works fine but if you would need to see it for some reason I can provide it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.