Inserting an Image into a Database?

Hi,

Whats the best way to post an Image to a Database?
I’m able to get the image uploaded to the server, But its outputting and inserting that string into the Database, I have a databae setup called “Ideas” and the image will need to sit in that table

Code for upload of image is as follows :

<head>
<title>Simple file upload script</title>
</head>
<body>
<?php 
if ($_REQUEST[completed] == 1) { 
       $source = "ideas/";
       move_uploaded_file($_FILES['filename']['tmp_name'],
               "$source".$_FILES['filename']['name']);
// Following code to fix line ends
       if (! eregi ('(gif|jpg|pdf)$',$_FILES['filename']['name'])) {
       $fi = file("$source".$_FILES['filename']['name']);
       $fi2 = fopen("$source".$_FILES['filename']['name'],"w");
       foreach ($fi as $lne) {
               $n = rtrim ($lne);
               fputs ($fi2,"$nn");
               }
       }
//
?>
Your idea has been added.
<?php } else { ?>
<br>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=150000>
<input type=hidden name=completed value=1>
Ideas' Image: <input type=file name=filename><br>
<input type=submit value="Add Idea">
</form><br>
<?php  } ?>
</body>
</html> 

But how do I insert that image string to the Database?

Cheers

Here is a tutorial that will teach you how to

http://hockinson.com/index.php?s=37

Sponsor our Newsletter | Privacy Policy | Terms of Service