How to scan a file for viruses in PHP
1 min readJul 31, 2019
Our Virus Scan API both useful and easy to employ. Let’s dive in.
First up, we need our reference:
"require": {
"cloudmersive/cloudmersive_virusscan_api_client": "^1.4"
}
We will use scanFile to examine the byte array or file buffer in question:
<?php
require_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');$apiInstance = new Swagger\Client\Api\ScanApi(
new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/file"; // \SplFileObject | Input file to perform the operation on.try {
$result = $apiInstance->scanFile($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling ScanApi->scanFile: ', $e->getMessage(), PHP_EOL;
}
?>
The results of the scan will now be provided to you along with the threat’s identity in the case of a positive.