# Php/mysql BlOb

**URL:** <https://forum.kirupa.com/t/php-mysql-blob/30193>\
**Category:** Uncategorized\
**Created:** [September 4, 2003, 11:19pm UTC](https://forum.kirupa.com/t/php-mysql-blob/30193 "2003-09-04T23:19:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jazzman121](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/jazzman121/32/127_2.png) [@jazzman121](https://forum.kirupa.com/u/jazzman121)\
**Post date:** [September 4, 2003, 11:19pm UTC](https://forum.kirupa.com/t/php-mysql-blob/30193/1 "2003-09-04T23:19:59Z")

</div>

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,…

```php

<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)

```php
$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

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 5, 2003, 6:55am UTC](https://forum.kirupa.com/t/php-mysql-blob/30193/2 "2003-09-05T06:55:55Z")

</div>

ok. try with only one file.

Form page:

```php

<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:

```php

$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

```php

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.

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 5, 2003, 7:12am UTC](https://forum.kirupa.com/t/php-mysql-blob/30193/3 "2003-09-05T07:12:44Z")

</div>

hwo do i do multiple uploads?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [September 5, 2003, 7:23am UTC](https://forum.kirupa.com/t/php-mysql-blob/30193/4 "2003-09-05T07:23:53Z")

</div>

the same way. remember to rename the

```php

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

```

for example

```php

//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.
