Looking to hire Laravel developers? Try LaraJobs

laravel-malware-validation-rule maintained by divineomega

Description
Scans uploaded files for viruses and other malware
Author
Last update
2026/02/15 00:29 (dev-master)
License
Links
Downloads
395

Comments
comments powered by Disqus

Laravel Malware Validation Rule

Build Status

The Laravel Malware Validation Rule package provides a validation rule that scans uploaded files for viruses and other malware.

Installation

To install the Laravel Malware Validation Rule package, run the following command

composer require jord-jd/laravel-malware-validation-rule

This package makes use of the ClamAV daemon to perform virus/malware scanning. You can install ClamAV in Ubuntu/Debian with the following command.

sudo apt install clamav-daemon

Your ClamAV installation should automatically update virus defintions. However, you can update your ClamAV virus definitions manually using the freshclam command. It is recommended to restart the ClamAV daemon after the virus definitions have been updated to ensure they take effect.

sudo freshclam
sudo service clamav-daemon restart

Usage

See the following basic usage example, which demonstrates how to validate a basic file upload does not contain contain a known virus/malware.

use \JordJD\LaravelMalwareValidationRule\Rules\Malware;

// ...

public function rules()
{
    return [
        'my_file' => ['required', 'file', new Malware()],
    ];
}

By default the validation rule message will include the name of the detected virus/malware. If you do not wish the malware name to be shown in the validation message you can turn this off as shown below.

public function rules()
{
    $showMalwareName = false;

    return [
        'my_file' => ['required', 'file', new Malware($showMalwareName)],
    ];
}