1

So I have a webcam widget to take snapshots from guests. My guest table have an image field and I want to store this pic on it. I tried storing raw binary data, base64 encoded data and it didn't works. I don't know if database is receiving correct data or if I don't dealing with returned data well. I'm using PDO in my app and I've read on the web that it can have an issue with data larger than 64 kb, anyone knows if it's true?

This is how I got the image data from the webcam:

$imagem = file_get_contents('php://input');

Like I said above I tried to store image's pure data $imagem and then this way:

$data = @unpack("H*hex", $imagem);
$imagem_bd='0x'.$data['hex'];

And for both of that I've tried encoding with base64 too, but none worked.

Just for information: This app I'm working is a remake of another similar app that have this feature too, but on this old app I's used TSQL and it works fine.

Thanks in adv.

EDIT

For now I have done the insert well, but I can't retrieve and render the image at the browser.

0

2 Answers 2

3

you can encode images in blob instead of base64. But i recommend you to store image as file and store the link to the image in database. As storing images in database may consume large space and also returning it can eat your server and also it may take more time to load compared to file system.

Sign up to request clarification or add additional context in comments.

2 Comments

Yeah, I know but it have to be preferably this way. How do you sugest encode as blob, how can I do this? Thank you.
www.techcubetalk.com/2009/01/tutorial-on-how-to-store-images-in-mysql-blob-field/ check that link.
1

If you use PreparedStatement, all you need to do is use bindValue, with your binary image:

$sql = "INSERT INTO your_table (image) VALUES (?)";
$stmt->bindValue(1, $imagem);
$stmt->execute();

Anyway, as said here, it's not a good idea to store images in the database.

About the 64KB limit, it depends of the data types of your columns in the table (in MySQL, the BLOB type has a limit of 64KB, but there is another types of data, like MEDIUMBLOB and LONGBLOB).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.