我有一台Mac服务器,我正在构建PHP代码,以允许用户上传图像,文档,甚至视频文件.研究这肯定让我感到紧张,我希望上传的内容是无病毒的.
正在建设自己将成为一个巨大的挑战?你会这样做,还是会找到一些OS或OTS产品?(你知道你能推荐的吗?)
从概念上讲,你所谈论的内容非常简单.接受和处理上传非常简单,绝对不是我认为您需要担心购买预先构建的解决方案.
通常像图像和视频这样的东西不能真正具有"病毒"(除非查看器应用程序真的很差并且让它们以某种方式运行代码 - 也称为"Internet Explorer"),但是如果它们无论如何都要进行病毒扫描并不是很困难.你想要.只需找到一个可以在服务器上运行的命令行扫描程序(类似Clam AV),每当上传文件时,通过扫描程序运行它,如果扫描失败,则拒绝上传(并记录事件).
如果您要上传非常大的文件,您可能还会考虑使用Flash上传/状态栏,以便用户可以查看上传了多少文件.SWFUpload是一个不错的选择.
您可以通过在PHP中执行以下操作来使用ClamAV扫描文件:
$out = ''; $int = -1; exec('/usr/local/bin/clamscan --stdout /path/to/file.ext', $out, $int); if ($int == 0) { print('No virus!'); } /* Return codes from clamscan: 0 : No virus found. 1 : Virus(es) found. 40: Unknown option passed. 50: Database initialization error. 52: Not supported file type. 53: Can't open directory. 54: Can't open file. (ofm) 55: Error reading file. (ofm) 56: Can't stat input file / directory. 57: Can't get absolute path name of current working directory. 58: I/O error, please check your file system. 59: Can't get information about current user from /etc/passwd. 60: Can't get information about user '' from /etc/passwd. 61: Can't fork. 62: Can't initialize logger. 63: Can't create temporary files/directories (check permissions). 64: Can't write to temporary directory (please specify another one). 70: Can't allocate memory (calloc). 71: Can't allocate memory (malloc). */