PHP code example of abdian / laravel-upload-guard

1. Go to this page and download the library: Download abdian/laravel-upload-guard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

abdian / laravel-upload-guard example snippets


// One rule. Fail-closed by default.
$request->validate([
    'file' => '

public function store(\Illuminate\Http\Request $request)
{
    $request->validate([
        'file' => '

$request->validate([
    'file' => '

use Abdian\UploadGuard\Rules\Safeguard;

$request->validate([
    'avatar' => ['
        ->stripMetadata(),
    ],

    'document' => ['red', (new Safeguard)
        ->documentsOnly(),   // archive + macro scanning are already on by default
    ],
]);

$request->validate([
    'avatar'   => 'vg',
    'document' => '000',
    'archive'  => '

'max_scan_size'   => 25 * 1024 * 1024, // files larger than this are rejected
'over_cap_policy' => 'reject',         // or 'header_only'

'mime_validation' => [
    'strict_check'       => true,
    'block_dangerous'    => true,
    'block_undetectable' => false,     // set true to reject unknown content types
],

'archive_scanning' => [
    'enabled'               => true,                 // ON by default
    'max_decompressed_size' => 500 * 1024 * 1024,    // hard cap on ACTUAL bytes (global)
    'max_files_count'       => 10000,
    'max_nesting_depth'     => 3,
],

'office_scanning' => [
    'enabled'       => true,           // ON by default
    'block_macros'  => true,
    'block_activex' => true,
],

'svg_scanning'   => ['mode' => 'sanitize'],                 // or 'reject'
'image_scanning' => ['max_pixels' => 64_000_000, 'reencode' => false],

'rate_limiting'  => ['enabled' => false],  // DoS guard (opt-in)
'quarantine'     => ['enabled' => false],  // forensic quarantine (opt-in)
bash
php artisan vendor:publish --tag=safeguard-config