Php/mysql BlOb

ok… here is my scripts dont know wats wrong it aint working maybe u guys can figure out wats wrong
I want to upload images (.jpg’s) to the database… ive defined the table with a coloum file as blob

here is the code for the form to update to the database,…


<form method="post" action="form.php?action=ft"  enctype="multipart/form-data">
<input type="file" name="userfile[]">
<input type="file" name="userfile[]">
<input type="submit" name="ftsubmit" value="Submit">
</form>

if($ftsubmit){
//update the image
	$path = "/ft_files/";
	$attach = $HTTP_POST_FILES['userfile'];
	if($attach['name'][0] != "none" && !empty($attach['name'][0]) && is_uploaded_file($attach['tmp_name'][0])) {
		$db->query("UPDATE $table_ft SET file='$attach[0]' WHERE id='0'");
	}
	if($attach['name'][1] != "none" && !empty($attach['name'][1]) && is_uploaded_file($attach['tmp_name'][1])) {
		$db->query("UPDATE $table_ft SET file='$attach[1]' WHERE id='1'");
	}

}

and here is the code to show the image on the page…(view image)

$count = 0;
$query = $db->query("SELECT * FROM $table_ft ORDER BY id");
while($ftlinks = $db->fetch_array($query)) {
$count++;
$ftimage[$count] = $ftlinks[file];
}


echo "<img src=$ftimage[0]>"
echo "<img src=$ftimage[1]>"


i am not sure if the image is uploading to the db or not… but before the fields were NULL when i created it after uploading it doesnt show anything in the command prompt…( so im assumiing some data is been written into the database )
please helpp

ok. try with only one file.

Form page:


<form method="post" action="insert.php" name="form1" enctype=multipart/form-data>
<input type=\"file\" name="binary_file" size="40">
<input type="submit" name=submit value="Submit"></form>

Insert file in the db with this script:



$self = isset($_SERVER) ? $_SERVER["PHP_SELF"] : $HTTP_SERVER_VARS["PHP_SELF"];


@mysql_connect("$host", "$user", "$password") or die("Connection  failed!");

@mysql_select_db($dbname);

$data = addslashes(fread(fopen($_FILES["binary_file"]["tmp_name"], "rb"), $_FILES["binary_file"]["size"]));

$result = @mysql_query("INSERT INTO files (Binary, Name, Size, Type)
VALUES ('$data','" . $_FILES["binary_file"]["name"] . "',
'" . $_FILES["binary_file"]["size"] . "','" . $_FILES["binary_file"]["type"] . "')")
or die("Insert failed !");

echo "File " . basename($_FILES["binary_file"]["name"]) . "uploaded.";
@mysql_close();

SQL file


CREATE TABLE files(
Id int(4) NOT NULL auto_increment,
Binary mediumblob NOT NULL,
Name varchar(50) NOT NULL default '',
Size int(10) NOT NULL default '0',
Type varchar(50) NOT NULL default '',
PRIMARY KEY (Id)
)

i think it would work.

hwo do i do multiple uploads?

the same way. remember to rename the


<input type="file\" name="binary_file" size="40">

for example


//first file
<input type="file\" name="binary1" size="40">
//second file
<input type="file\" name="binary2" size="40">

and modify the php script with the new input file names.