Get expert guidance in a few days with a Laravel code review

Clamav Validator

sunspikes/clamav-validator image

Clamav Validator stats

Downloads
647.7K
Stars
291
Open Issues
10
Forks
65

View on GitHub →

Custom Laravel 5 anti-virus validator for file uploads.

ClamAV Virus Validator For Laravel

A custom Laravel virus validator based on ClamAV anti-virus scanner for file uploads.

Requirements

You must have ClamAV anti-virus scanner running on the server to make this package work.

You can see the ClamAV installation instructions on the official ClamAV documentation.

For example on an Ubuntu machine, you can do:

# Install clamav virus scanner
sudo apt-get update && sudo apt-get install -y clamav-daemon
 
# Update virus definitions
sudo freshclam
 
# Start the scanner service
sudo systemctl enable --now clamav-daemon clamav-freshclam

This package is not tested on Windows, but if you have ClamAV running (usually on port 3310) it should work. You will also need to have sockets extension installed and enabled (all executions without this module will fail with this error - "Use of undefined constant 'AF_INET'").

Installation

1. Install the package through Composer.

$ composer require sunspikes/clamav-validator

2. Add the service provider (for Laravel 5.4 or below)

This package supports Laravel new Package Discovery.

If you are using Laravel < 5.5, you need to add Sunspikes\ClamavValidator\ClamavValidatorServiceProvider::class to your providers array in config/app.php:

'providers' => [
// ...
 
Sunspikes\ClamavValidator\ClamavValidatorServiceProvider::class,
],

3. Publish assets from the vendor package

Config file

The default configuration file does use ENV to override the defaults. If you want to change the configuration file anyway you run the following command to publish the package config file:

php artisan vendor:publish --provider="Sunspikes\ClamavValidator\ClamavValidatorServiceProvider" --tag=config

Once the command is finished you should have a config/clamav.php file that will be used as well.

Language files

If you want to customize the translation or add your own language you can run the following command to publish the language files to a folder you maintain:

php artisan vendor:publish --provider="Sunspikes\ClamavValidator\ClamavValidatorServiceProvider" --tag=lang

This will copy the language files to resources/lang/vendor/clamav-validator for Laravel >= 5.1

Usage

Use it like any Validator rule:

$rules = [
'file' => 'clamav',
];

ClamavValidator will automatically run multiple files one-by-one through ClamAV in case file represent multiple uploaded files.

Author

Krishnaprasad MG [@sunspikes] and other awesome contributors

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Sunspikes Clamav Validator Related Articles

ClamAV Scanner for Flysystem image

ClamAV Scanner for Flysystem

Read article
ClamAV Anti-Virus Validator for Laravel image

ClamAV Anti-Virus Validator for Laravel

Read article
Laravel Cloud logo

Laravel Cloud

Easily create and manage your servers and deploy your Laravel applications in seconds.

Laravel Cloud
Harpoon: Next generation time tracking and invoicing logo

Harpoon: Next generation time tracking and invoicing

The next generation time-tracking and billing software that helps your agency plan and forecast a profitable future.

Harpoon: Next generation time tracking and invoicing
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
Get expert guidance in a few days with a Laravel code review logo

Get expert guidance in a few days with a Laravel code review

Expert code review! Get clear, practical feedback from two Laravel devs with 10+ years of experience helping teams build better apps.

Get expert guidance in a few days with a Laravel code review
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell
Kirschbaum logo

Kirschbaum

Providing innovation and stability to ensure your web application succeeds.

Kirschbaum