当对表单传递过来的参数用 htmlspecialchars 对特殊字符(& ,' ," , )进行编码时(由于插入数据库安全过滤的需要),会出现如下问题。
如果用户上传了一个文件是带有特殊字符的,如 ' ,文件名保存到数据库就会发生以下问题。

如果你服务器端的 PHP 代码是通过 $_GET['id'] 间接来获取它的文件名,然后以名称传输到客户端。
<?php
$name = mysql_query('SELECT name FROM accessories');//通过 ID 获取文件名
//......获取文件......
$file_path = ROOT_PATH . '/uploads/accessories/'. $name;
header ( 'Content-Disposition: attachment; filename=' . urlencode ( $name ) );
header ( 'Content-type: application/octet-stream;' );
header ( 'Content-Length: ' . filesize ( $file_path ) );
readfile ( $file_path );
exit ();
?>?那么下载的时候就会出现如下文件名错误。
立即学习“PHP免费学习笔记(深入)”;

个人主页: https://plus.google.com/+sherlockwang/posts
原文链接:http://woqilin.blogspot.com/2012/10/php-htmlspecialchars.html
以上就介绍了PHP 中用 htmlspecialchars 对特殊字符进行编码的弊端,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号