【发布时间】:2014-02-04 18:54:26
【问题描述】:
我的 php 项目中有文件上传系统。
我在上传时所做的:
1) 检查文件扩展名和文件 mime 类型。
2)如果扩展名和mime类型是允许的类型,我将文件保存在public_html目录之外,然后,我给用户机会,下载文件:
if (file_exists($file_path)) {
header('Content-Description: File Transfer');
header('Content-Type: some mime type');
header('Content-Disposition: attachment; filename=somefilename');
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file_path));
readfile($file_path);
}
问题:上传文件的这个步骤,是否安全?如果没有,还有什么可以提高上传文件的安全性?
谢谢。
【问题讨论】:
标签: php security file-upload