How to virus scan an HTML file in PHP

Setting up virus scanning in PHP can be a long and arduous task. That’s why today’s post covers how to set up this functionality in a tiny fraction of the time. Let’s jump right into it.

Installation is our first step, accomplished by running this snippet in your command line of Composer.

composer require cloudmersive/cloudmersive_virusscan_api_client

Wait for installation to complete, then we can call our function, like so.

<?phprequire_once(__DIR__ . '/vendor/autoload.php');// Configure API key authorization: Apikey$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');// Uncomment below to setup prefix (e.g. Bearer) for API key, if needed// $config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKeyPrefix('Apikey', 'Bearer');$apiInstance = new Swagger\Client\Api\ScanApi(// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.// This is optional, `GuzzleHttp\Client` will be used as 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;}?>

Well that was easy, right? Our results will be returned from the API and we can all enjoy the rest of our day without worrying about viruses causes problems in our servers.

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