How to virus scan a TAR file in PHP

Got an influx of sketchy archive files that you need to vet? We have the perfect PHP-based solution for you. It’s fast, free, and sets up in minutes. Let’s dive in.

First up, install our virus scan API client via the command line of Composer.

composer require cloudmersive/cloudmersive_virusscan_api_client

OK, now that the client is installed, move on to calling our virus scan 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 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;}?>

Boom! We’re done! Yup, it’s seriously that simple. We have a ton of other useful APIs like this that are just as easy to set up, so go and take a gander.

Image for post
Image for post

Written by

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