8 Replies - 85385 Views - Last Post: 05 June 2012 - 10:50 AM

#1 fliers002  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 26-November 07

how to insert picture in mysql database

Post icon  Posted 26 November 2007 - 05:27 AM

how to insert picture in mysql database

This post has been edited by fliers002: 26 November 2007 - 05:28 AM

Is This A Good Question/Topic? 0
  • +

Replies To: how to insert picture in mysql database

#2 ReggaetonKing  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 4
  • View blog
  • Posts: 73
  • Joined: 16-November 06

Re: how to insert picture in mysql database

Posted 26 November 2007 - 05:40 AM

Do you have to store the actual picture in the database? Why don't you just upload it into a directory and store the path to that directory with the picture name in the database instead.
Was This Post Helpful? 0
  • +
  • -

#3 Wynona  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 05-December 07

Re: how to insert picture in mysql database

Posted 05 December 2007 - 04:36 AM

View PostReggaetonKing, on 26 Nov, 2007 - 05:40 AM, said:

Do you have to store the actual picture in the database? Why don't you just upload it into a directory and store the path to that directory with the picture name in the database instead.




hey guys ( i assumed you guys... are indeed guys!)

i'm new here.. and this is exactly my problem too.. is there a way to get JPEG files into the database? using... MySQL? please help! i mean... other than using the mentioned method above..
Was This Post Helpful? 0
  • +
  • -

#19 nav33n  Icon User is offline

  • D.I.C Head

Reputation: 7
  • View blog
  • Posts: 71
  • Joined: 02-October 07

Re: how to insert picture in mysql database

Posted 05 December 2007 - 04:48 AM

<?php		
$con=mysql_connect($host,$user,$pass);
mysql_select_db($db);

	if(isset($_REQUEST['submit']))
	{	

		$imgtype=$_FILES['uploadfile']['type'];
		$name=$_REQUEST['name'];

		if($imgtype=="image/jpeg" || $imgtype=="image/jpg" || $imgtype=="image/pjpeg" || $imgtype=="image/gif" || $imgtype=="image/x-png" || $imgtype=="image/bmp")
		{
					
			$image=$_FILES['uploadfile']['tmp_name'];
			$fp = fopen($image, 'r');
			$content = fread($fp, filesize($image));
			$content = addslashes($content);
			fclose($fp);
			$sql="insert into table (name,image) values ('$name','$content')";
			$res=mysql_query($sql) or die (mysql_error());
	   }
	}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD><TITLE>Test</TITLE>
<META http-equiv=Content-Type content="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<form name="form" method="post" ENCTYPE="multipart/form-data" action="image_upload.php">
<table>
	<tr>
		<td>Name: <input type="text" name="name"></td>
	</tr>
	<tr>
		<td >
			Upload image: <input type="file" name="uploadfile"> 
		</td>
	</tr>
	<tr>
		<td><input name="submit" value="submit" type="submit"> </td>
	</tr>
</table>
</form>
</BODY>
</HTML>



This is how you upload an image to the table.
Was This Post Helpful? 1

#20 Trogdor  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 15
  • View blog
  • Posts: 627
  • Joined: 06-October 06

Re: how to insert picture in mysql database

Posted 07 December 2007 - 05:57 AM

using addslashes is not safe enough.
You are better off encoding it using for example base64encode.
Was This Post Helpful? 0
  • +
  • -

#21 dataferret  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 13-December 07

Re: how to insert picture in mysql database

Posted 13 December 2007 - 10:50 AM

View PostTrogdor, on 7 Dec, 2007 - 05:57 AM, said:

using addslashes is not safe enough.
You are better off encoding it using for example base64encode.

I think you can store the JPG or GIF binary image data itself as a Binary Large Object (BLOB) field but it is not my area of expertise. However it should point you in the right direction.
Was This Post Helpful? 0
  • +
  • -

#25 fsloke  Icon User is offline

  • D.I.C Regular

Reputation: 25
  • View blog
  • Posts: 412
  • Joined: 19-December 07

Re: how to insert picture in mysql database

Posted 19 December 2007 - 11:14 PM

We not store whole picture into database....

But you can store the location of the picture....

Then use programming language to display the images....

Example: C:/store/image/smile.bmp

-lol.....
Was This Post Helpful? 1

#26 vishnuraj910  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-June 12

Re: how to insert picture in mysql database

Posted 05 June 2012 - 10:05 AM

Thank you for this info. I stored the image in database.
But how can we open this stored image again?
Was This Post Helpful? 0
  • +
  • -

#27 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: how to insert picture in mysql database

Posted 05 June 2012 - 10:50 AM

Please refer to Martyr2's excellent blog entry on this subject.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1