PHP code example of kraenzle-ritter / clamav-scan

1. Go to this page and download the library: Download kraenzle-ritter/clamav-scan library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kraenzle-ritter / clamav-scan example snippets


use KraenzleRitter\ClamavScan\ClamdScanner;

$scanner = new ClamdScanner('unix:///var/run/clamav/clamd.ctl'); // or tcp://clamav:3310

if (! $scanner->isAvailable()) {
    // clamd is not running: skip, or fail if a scan is ck the file, see $result->message

$result = $scanner->scanRange('/path/to/film.mp4', 268_435_456, 268_435_456);

new ClamdScanner(
    socket: 'tcp://clamav:3310',  // unix://…, tcp://…, or a bare path
    timeout: 30.0,                // seconds, to connect and per read/write
    chunkSize: 65536,             // bytes per INSTREAM chunk
);

use KraenzleRitter\ClamavScan\FakeScanner;

$scanner = new FakeScanner(
    infected: ['*/virus.exe' => 'Win.Trojan.Fake'],
    errors: ['*.iso' => 'INSTREAM size limit exceeded.'],
);

$scanner->scanned();            // every path it was asked to scan
FakeScanner::unavailable();     // behaves like a clamd that is not running