简体   繁体   中英

Insert image in database mysql

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM