store a pdf in mysql

删除回忆录丶 提交于 2019-12-01 19:31:13

Put it in the database, but the blob datatype probably wont cut it. The mediumblob is normally sufficient.

Mysql Datatypes

BLOB, TEXT                L + 2 bytes, where L < 216
MEDIUMBLOB, MEDIUMTEXT    L + 3 bytes, where L < 224
LONGBLOB, LONGTEXT        L + 4 bytes, where L < 232

I've used this several times with very good results. Be sure to save the filesize too, as it makes it easier to retrieve it. Not sure if it applies to C# as it does to PHP.

If using prepared statements with parameters the data will automatically be escaped AFAIK.

Also i can see no real reason as to why the database itself would get slow when storing this type of data in it. The main bottleneck will och course be the transfer of the data. Also mysql is sometimes restrictive about the maximum length of queries and the responses in particular.

Once you have it running, it's pretty neat, especially when dealing with lots of small files. For a small number of large files, this approach does not make sense, better use some backup system to deal with moved/deleted files.

http://www.phpriot.com/articles/images-in-mysql is a good tutorial with some background information, and an implementation of storing images in MySQL

Honestly, I think that going with links instead of actually inserting the file into the database is the best way to go. Doing that will make the database very slow, and will be more trouble than its worth.

I would upload the files to a designated folder like "certificates" and made the certificate names go with a client number so they are easy to find and edit, remove etc. I have seen people store images in databases but even that is advised against.

If the method you wish is definitely a must, check out this article:

http://www.wellho.net/mouth/1001_-pdf-files-upload-via-PHP-store-in-MySQL-retrieve.html

It explains how to store, and retrieve .pdf files in a mySQL Database.

Best of luck!

I considered putting the PDFs in a folder and storing their location as a varchar in the customer's record, but if the PDFs get moved/deleted/etc. then we're up a creek.

That's the approach I would take. Then using some logic perhaps some BPEL type stuff - detect if any of the files move/delete and fire off a trigger to your DB to properly update the location/remove the location

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!