My web application needs to virus-check uploaded files. So I need to install ClamAV, schedule updates, and test virus scanning from PHP scripts.
sudo apt-get install clamav clamav-daemon clamav-freshclam
So that’s clamav installed. Next up – test it from the command line.
sudo clamscan test.pdf
That works, although it’s suspiciously slow.
Next – test from a PHP script:
- Copy test.pdf into Apache’s DocumentRoot directory
- Write a PHP script there, called scan.php
- Must contain a (call to a) function virus_scan()…
function virus_scan($path) { $command = 'clamscan ' . escapeshellarg($path); $out = ''; $int = -1; exec($command, $out, $int); return $int == 0; }
Hooray.