简体   繁体   English

在数据库mysql中插入图像

[英]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 将插入照片的列是LONGBLOB

1) How can this be done to be fine when I upload 1 or more photos? 1)当我上传1张或多张照片时,如何做到最好?

2) Since there is just one column, how can I extract all of them? 2)由于只有一列,如何提取所有列? 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/ 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. 基本上,您必须在默认上传后打开图像文件,但不要将其移动到最终目录,而是将其保留在临时PHP文件夹中。 You would open the file, get all its content and encode with base64. 您将打开文件,获取其所有内容并使用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"> 为了显示图像,我认为,不是完全确定,您可以检索值,对其进行解码,然后直接用于<img src="value">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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