2

I am tring to upload an image to a blob field and just created a field on type blob, thinking that was it...but I get all types of different things over the net..so now I have this:

<form id="form" method="post" enctype="multipart/form-data">
<input type="file" name="thumbnail" />

...then to save:

$thumbnail = $_REQUEST['thumbnail'];

//Not sure about this:
$fileName = $_FILES['thumbnail']['name'];
 $tmpName = $_FILES['thumbnail']['tmp_name'];
 $fileSize = $_FILES['thumbnail']['size'];
 $fileType = $_FILES['thumbnail']['type'];

and finally:

$sql = "insert into users(firstname,lastname,phone,email,thumbnail) values('$firstname','$lastname','$phone','$email','$thumbnail')";

I'm I on the right track? Do I need to create fields for: name, tmp_name,size and type or just keep the 1 field I have ... The Blob field?

Satch3000
  • 47,356
  • 86
  • 216
  • 346

2 Answers2

0

You might be able to solve this using what's known as a prepared statement.
Essentially it allows you to make a "prepared SQL statement" then safely replace the components with data. Not only does it help prevent injection attacks, but it also sanitizes your data.

If that doesn't suit your needs, you can always convert the binary data to a hex string using the unpack function.

Mr. Llama
  • 20,202
  • 2
  • 62
  • 115
0

Check these threads about MYSQL storing images as BLOBs.

To Do or Not to Do: Store Images in a Database

Insert Blobs in MySql databases with php

The general recommendation is: do not store images in MySQL as the growth is hard to manage and the performance could degrade. Also, using your images on the fly will require you to transform them back, with an additional cost. There's no better and cheaper file handler than your own server OS.

Community
  • 1
  • 1
Alfabravo
  • 7,493
  • 6
  • 46
  • 82