1

I want to save an image to the database using SQLite. I send the image via <input type='file'> in HTML, get the file in the $_FILES var in PHP, and after this, what I should do?

I created a BLOB field in the database. Currently I'm using SQLite 2.1, because that is the limitation of my homework.

Should I convert an image to binary to store in a database or do something else?

5
  • 1
    You may want to consider storing the files on the filesystem, and then storing the image name/path in your database. Makes management easier down the road. Commented Jun 7, 2011 at 18:00
  • Because it's a homework, I need to store in the database. Commented Jun 7, 2011 at 18:01
  • @ben: i don't think that makes the management easier. Commented Jun 7, 2011 at 18:08
  • @yes: I would argue for it because it gives me full access to my image store without needed to go into a db and select bytes to save as an image. Commented Jun 7, 2011 at 18:30
  • @Ben: actually to get access to your image in your case you need Access to your DB then access your File System. While storing into DB you just need the access to DB Commented Jun 7, 2011 at 18:31

1 Answer 1

2

you can do $image = file_get_contents( $_FILES['file']['tmp_name'] );

And then upload it into your blob column (of course it needs to be escaped before, PDO)

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

1 Comment

I used an base64_encode to write the data to the database after this.

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.