是否需要使用mysql_real_escape_string()将图像导入mysql?
例如:
$data = file_get_contents($_FILES['image']['tmp_name']);
$data = mysql_real_escape_string($data);
mysql_query("INSERT INTO table set image='$data'....
这是坚持的正确方法吗?
For example:
$data = file_get_contents($_FILES['image']['tmp_name']);
$data = mysql_real_escape_string($data);
mysql_query("INSERT INTO table set image='$data'....
Is this a correct way to stick with?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以执行
base64_encode
来保持数据的完整性,并确保您不会遇到任何类型的字符问题,实际上这是保存和传输数据的一种非常常见的方式。要取回它,请使用base64_decode
。You could do a
base64_encode
to keep the integrity of your data, and assure that you will not have problems with characters of any kind, actually it is a very common way to keep and transfer data. And to get it back usebase64_decode
.我建议保留它,除非有理由删除它,因为它是防止 sql 注入的好方法。请参阅此处: http://php.net/manual/en/ function.mysql-real-escape-string.php 。
很可能通过用户上传的图像或客户端可能意外使用的图像进行 SQL 注入。
不使用它的一个原因可能是性能。我倾向于推荐安全性而不是性能。
I would recommend keeping it unless there is a reason to remove it, as its a good way to prevent sql injection. See here: http://php.net/manual/en/function.mysql-real-escape-string.php .
It is probably possible to do sql injection through an image that a user could upload or a client could accidentally use.
A reason not to use it could be performance. I would tend to recommend security over performance.