简体   繁体   English

PHP / SQL图片上传到数据库

[英]PHP / SQL picture upload to a database

I need a php code and sql code that will let someone upload an image to a database. 我需要一个PHP代码和SQL代码,让某人将图像上传到数据库。 The only thing I can find is very glictchy and not accepted by some browsers. 我唯一能找到的东西是非常粗俗的,一些浏览器不接受。 Any ideas? 有任何想法吗?

NEVER store images in the database. 切勿将图像存储在数据库中。 NEVER EVER EVER EVER. 永远不会永远。 There are tons of other questions posted here about it that you may want to ready up on. 这里有很多关于它的问题,你可能想要准备好。

Always store directly on filesystem, and store the image URL of the file in the database. 始终直接存储在文件系统上,并将文件的图像URL存储在数据库中。

If I understood correctly, you want to upload image files (or any files) via browser to the server and save them in the database. 如果我理解正确,您希望通过浏览器将图像文件(或任何文件)上传到服务器并将其保存在数据库中。 If that is the case, read this: 如果是这种情况,请阅读:

http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx

There are likely lots of available tutorials online to show you how to do this (you might take a look at this one: http://www.codewalkers.com/c/a/Database-Articles/Storing-Images-in-Database/ ). 网上有很多可用的教程可以告诉你如何做到这一点(你可以看看这个: http//www.codewalkers.com/c/a/Database-Articles/Storing-Images-in-Database / )。

I think that this is not the most efficient way to handle images, however. 但是,我认为这不是处理图像的最有效方式。 You might consider writing them to a folder and simply keep the name of the file and its location in the database. 您可以考虑将它们写入文件夹,只需将文件名及其位置保留在数据库中即可。 This stackoverflow question might help: How to store file name in database, with other info while uploading image to server using PHP? 这个stackoverflow问题可能会有所帮助: 如何在使用PHP将图像上传到服务器的同时将文件名存储在数据库中以及其他信息?

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

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