Table structure:
CREATE TABLE binary_data (
id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
description CHAR(50),
bin_data LONGBLOB,
filename CHAR(50),
filesize CHAR(50),
filetype CHAR(50)
);
Store binary data into SQL Database
// code that will be executed if the form has been submitted:
if ((isset($_POST['submit']))&&(isset($_FILES['form_data']))) {
upload();
} else {
show_form();
}//end if
function upload()
{
//includes
require("conn.php");
//define variables
$image_file = '';
$image_desc = '';
$type = '';
$size = 0;
$name = '';
$image_file = $_FILES['form_data']['tmp_name'];
$image_desc = $_POST['form_description'];
$type = $_FILES['form_data']['type'];
$size = $_FILES['form_data']['size'];
$name = $_FILES['form_data']['name'];
$data = fread(fopen($image_file, "r"), filesize($image_file));
$data = addslashes($data);
$result=connect("INSERT INTO binary_data (description,bin_data,filename,filesize,filetype) ".
"VALUES ('$image_desc','$data','$name','$size','$type')");
$id= mysql_insert_id();
print "This file has the following Database ID: $id";
//show the form again to load the next image
show_form();
}
function show_form()
{
// else show the form to submit new data:
?>
}
?>