Home  >  Article  >  Backend Development  >  PHP implementation logic for detecting whether files have viruses

PHP implementation logic for detecting whether files have viruses

藏色散人
藏色散人forward
2020-03-29 17:09:112673browse

After the user receives the sent file, he must be able to detect whether the file is a virus. The core software is clamav, which can be executed on the Linux command line to detect viruses in files or directories

Recommended : PHP video tutorial

For downloading and installation, please refer to other technical articles.

It should be noted that you need to enable

LocalSocket /tmp/clamd.socket

in the configuration file

When running, a clamd program is run as a daemon. When detecting, you only need to Call the following command

/usr/local/clamav-0.102.1/bin/clamdscan File

The response information is the following content

/usr/local/clamav-0.102.1/bin/clamdscan /tmp/attachment_04613DE5A94DD00E1F48F7A5D39A802C9700000000000001_4
/tmp/attachment_04613DE5A94DD00E1F48F7A5D39A802C9700000000000001_4: Xls.Virus.Mailcab-6702020-0 FOUND
----------- SCAN SUMMARY -----------
Infected files: 1
Time: 0.176 sec (0 m 0 s)

Call the exec function in PHP and call the above command to achieve detection

    $cmd="/usr/local/clamav-0.102.1/bin/clamdscan {$file}";
    exec($cmd,$output);

PHP implementation logic for detecting whether files have viruses

The above is the detailed content of PHP implementation logic for detecting whether files have viruses. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete