Storing Files in a Database

A new featured module has been added into my corporate site. It called "Arsip Digital" and laid on left side of profiles page. The "Arsip Digital" functioned as a storage groups of decision letters and revolver letters (SK & SE). It was designed & programmed by my self since it was requested after last meeting with the officials.

The "Arsip Digital" is a kind of electronic document (e-doc) stored on a web server - specificly saved in a database row. Some people might says as a digital archieves.

The e-doc technology can create paperless methode in companies and significantly reducing the budget spend of both papers, inks, duplicates and conventional mails. You can retrieved the archieves whereever and whenever you are as long as you have connected to the internet.

What is the secret behind the e-doc? Well, it is so simple. I used to take profit from the existence of BLOB (Binary Large OBject) data types. Have a clearly see an PHP example below:

$get_image = "your SQL query";
$get_image_result = @mysql_query($get_image) or die("Couldn't get image.");

$binary_file = @mysql_result($get_image_result,0,'BLOB_field");
$type_file = @mysql_result($get_image_result,0,"type_file");

header("Content-Type: application/$type_file");
header("Content-Length: ".filesize($binary_file));
echo "$binary_file";

The script above is the core process of how to retrieve the data stored on a BLOB types. Don’t forget to manually add some encrypt decrypt funtions to secure your code. Any questions?


Eko Wahyudiharto
PS: If you've benefit from this blog,
you can support it by making a small contribution.

Enter your email address:

Delivered by FeedBurner

Post a Comment Bookmark and Share


Post a Comment

Leave comments here...