且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用PHP在MySQL数据库中插入大文件?

更新时间:2023-01-30 16:51:02

据我所知,通常不将文件存储在db中是一种更快,更好的做法,因为它会很快变得庞大并使其变慢.***的办法是将文件存储在目录中,然后仅将文件的位置存储在数据库中.

As far as I know it's generally quicker and better practice not to store the file in the db as it will get massive very quickly and slow it down. It's best to make a way of storing the file in a directory and then just store the location of the file in the db.

我们为工作中的CMS中的images/pdfs/mpegs等执行此操作,方法是为使用url安全文件名命名的文件创建一个文件夹,并将该文件夹名称存储在db中.然后,只需在表示层中将其网址写出即可.

We do it for images/pdfs/mpegs etc in the CMS we have at work by creating a folder for the file named from the url-safe filename and storing the folder name in the db. It's easy just to write out the url of it in the presentation layer then.