Jeg har tidligere brugt følgende:
indsæt i database: <indiblob.php>
<HTML>
<HEAD>
<TITLE>Insert Binary Data in a Database</TITLE>
</HEAD>
<BODY>
<H1>Upload a File:</H1>
<FORM enctype="multipart/form-data" method="post" action="<? echo $PHP_SELF; ?>">
<INPUT type="file" name="img1" size="30">
<br><br>
<INPUT type="submit" name="submit" value="Use this File">
</FORM>
</BODY>
</HTML>
<?
if (!isset($img1)) {
header("Location:
http://www.website.com/insert_file.html");
exit;
}
$db = @mysql_connect("localhost", "username","password") or die("Can't connect to server.");
@mysql_select_db("userdata", $db) or die("Can't select database.");
$binary_junk = addslashes(fread(fopen($img1, "r"), filesize($img1)));
$insert_data = "INSERT INTO images (img_id, binary_junk, filename, filesize, filetype)
VALUES ('', '$binary_junk', '$img1_name', '$img1_size', '$img1_type')";
@mysql_query($insert_data) or die("Couldn't insert data.");
?>
Hent fra database:<udfrablob.php>
<?
$db = @mysql_connect("localhost", "username", "password") or die("Can't connect to server.");
@mysql_select_db("userdata", $db) or die("Can't select database.");
$get_image = "select binary_junk, filetype from images where img_id = 7";
$get_image_result = @mysql_query($get_image) or die("Couldn't get image.");
$binary_junk = @mysql_result($get_image_result,0,"binary_junk");
$filetype = @mysql_result($get_image_result,0,"filetype");
header("Content-type: $filetype");
print "$binary_junk";
?>