【发布时间】:2013-12-13 18:38:27
【问题描述】:
我将转换后的 base64 编码字符串存储为图像文件。我必须将文件作为字符串获取。
目前我通过 POST 获取字符串,我担心有人发布了一些他们可能会用来破坏服务器的内容。我的问题是如何确保它尽可能安全。
这就是它目前的工作方式(总结):
$encodedString = $_POST['image'];
// Strip the crud from the front of the string [1]
$encodedString = substr($encodedString,strpos($encodedString,",")+1);
// Cleanup File [2]
$encodedString = str_replace(' ','+',$encodedString);
// Decode string
$decoded = base64_decode($encodedString);
// Save File
file_put_contents(uniqid().'.png',$decoded);
接下来我应该怎么做才能确保有人没有/没有将一些恶意代码注入到 post 变量中?
或者有比 POST 更好的方法吗?
参考资料:
【问题讨论】:
-
很棒的链接!谢谢,他们非常有帮助。