How to virus scan a RAR archive in PHP

Cloudmersive
1 min readMar 6, 2020

--

Virus scanning is crucial in this web-based day and age. Generally speaking, it’s not usually a very simple endeavor, however. Today, that’s going to change. I present to you a Cloudmersive API ready to simplify this task for you. Let’s look at how to implement it.

First, just install the API client. Run this command in the Composer command line to begin:

composer require cloudmersive/cloudmersive_virusscan_api_client

Now we can call scanFile from the API and get it to work on our file.

<?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 default.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;}?>

Alright, that’s a wrap. Yeah, it’s really that easy to implement this virus scanning solution.

--

--

Cloudmersive
Cloudmersive

Written by Cloudmersive

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

No responses yet