2

I want to insert one or more photos on a database using this:

<input type="file" name="images" multiple="multiple" accept="image/x-png, image/gif, image/jpeg"/> 

The column where the photo will be inserted is LONGBLOB

1) How can this be done to be fine when I upload 1 or more photos?

2) Since there is just one column, how can I extract all of them? But just 2 of them?

2
  • What have you already tried? Your question should include this. Also, please describe why you want to store images in your database, because it's usually undesirable. Commented May 19, 2014 at 19:53
  • IMHO: If you are going to insert an image into a database, you should create a new row for every image. That way, each longblob column contains no more than 1 image. (Also, storing images in databases is rarely done More often, the relative path to the file asset of that image is saved) Commented May 19, 2014 at 19:54

1 Answer 1

1

I never get why people are questioning the reason before answer him. He needs an answer, not a avaliation. What if he is studying something?...

For each image you must create a row, that is the better way to organize things. Follow this tutorial and you should be able to save and retrieve images from database:

http://kennykee.com/92/saving-image-to-database-using-php/

Basicaly, you have to open you image file after a default upload, but don't move it to final directory, leave it at temporary PHP folder. You would open the file, get all its content and encode with base64. It would generate a long string. Save that to database.

To show the image, I think, not entirely sure, you would retrieve the value, decode it and use directly to <img src="value">

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

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.