How to scan a file for viruses in PHP

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:

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(),
$input_file = "/path/to/file"; // \SplFileObject | Input file to perform the operation on.
try {
$result = $apiInstance->scanFile($input_file);
} 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.

There’s an API for that. Cloudmersive is a leader in Highly Scalable Cloud APIs.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store