php:扭转 mysql_real_escape_string 对二进制文件的影响
我构建了一个网页,用户可以在其中提交 PDF,然后将其插入到 Mediumblob 中的 MySQL 数据库中,以便稍后检索。
这一切都工作正常,除非 PDF 包含图像或嵌入字体,在这种情况下图像会损坏并且使用该字体的任何文本都会消失(Acrobat 显示有关丢失字体的消息)。
我已经确定问题是由于我通过 mysql_real_escape_string_function 传递 pdf 数据而发生的。 我已在提交/检索时切换到 base64_encode/base64_decode,这解决了所有新文件的问题,但我已经提交了大约 25 个 PDF,我需要能够阅读。
是否可以逆转 mysql_real_escape_string 的影响? 或者这些文件是否已损坏且无法修复?
I built a webpage where users can submit a PDF which is then inserted into a MySQL database in a mediumblob for retrieval later.
This all works fine, except when the PDF contains images or embedded fonts, in which case the images are corrupted and any text using the font disappears (Acrobat display a message about the missing font).
I've determined the problem occurs from my passing the pdf data through the mysql_real_escape_string_function. I have switched to base64_encode/base64_decode on submission/retrieval which fixed the problem for all new files, but I have about 25 already submitted PDFs I need to be able to read.
Is it possible to reversed the effects of mysql_real_escape_string? Or are these files damaged beyond repair?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
当然,应该可以修复。 您只需要弄清楚 mysql_real_escape_string 的作用。 我相信您只需要删除紧邻 CR、LF、TAB、单引号、双引号、NUL 或其他斜杠之前的任何斜杠。 应该是单行正则表达式修复。
Sure, should be fixable. You just need to figure out exactly what mysql_real_escape_string does. I believe you just need to remove any slashes that immediately precede a CR, LF, TAB, single-quote, double-quote, NUL, or another slash. Should be a one-line regexp fix.
mysql_real_escape_string()
将反斜杠添加到这些字符中。问题是,如果您的二进制输出带有反斜杠(它是二进制数据),则可能很难修复。 话虽如此,没有什么神奇的功能可以撤销这个功能。
mysql_real_escape_string()
puts backslashes to these characters.The thing is, that if your binary output has backslashes it it's binary data, it can be very hard to fix. That being said, there is no magical function to undo this function.
老实说,我不知道还能是什么。 当我更改那段代码时,它解决了问题,并且我在网上发现了其他实例,人们也遇到了同样的问题(但没有解决方案)。
这是插入代码:
这是提取代码:
I honestly don't know what else it could be. When I changed that bit of code it cleared up the problem, and I've found other instances online where people had the same problem (but no solutions).
Here is the insertion code:
And here is the extraction code:
Ólafur,
我从 php 手册中收集到了这一点,甚至尝试了以下方法:
这在处理文本时似乎工作正常,但将其应用于二进制数据只会进一步降低 PDF 的质量(例如,段落丢失)。
Ólafur,
I gathered that from the php manual, and even tried the following:
This seems to works fine when dealing with text, but applying it to the binary data only further degrades PDF (e.g. paragraphs go missing).