Skip to content

emka.web.id

writing knowledge, recording civilization

Menu
  • Home
  • Tutorial
  • Search
Menu

Cara Melindungi Upload File dengan Pemindaian Malware di PHP

Posted on May 14, 2024

Unggahan file berbahaya dapat melewati deteksi antivirus tradisional. Artikel ini membahas cara menggunakan API gratis untuk memindai file upload pada formulir PHP dari ancaman malware.

Pemindaian Malware Gratis

Dengan API gratis, kita dapat melakukan pemindaian tanda tangan malware dan pemindaian ancaman deterministik pada file yang diunggah. API ini mencakup lebih dari 17 juta ancaman virus dan malware, serta memungkinkan penetapan aturan khusus untuk memblokir kode berbahaya seperti skrip, makro, dan lainnya.

Mulai dengan API Key Gratis

API menyediakan key gratis dengan batasan 800 panggilan per bulan. Kita dapat menggunakan contoh kode di bawah ini untuk menyusun panggilan API:

Instalasi Perangkat Klien PHP

Pertama, kita perlu instal perangkat klien PHP menggunakan Composer:

composer require cloudmersive/cloudmersive_virusscan_api_client

Memanggil Fungsi Pemindaian

Selanjutnya, kita dapat memanggil fungsi pemindaian dengan penyesuaian aturan sesuai kebutuhan:

<?php
require_once(__DIR__ . '/vendor/autoload.php');

// Konfigurasi API key
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');

$apiInstance = new Swagger\Client\Api\ScanApi(
    
    
    new GuzzleHttp\Client(),
    $config
);

$input_file = "/path/to/inputfile"; // File yang akan dipindai
$allow_executables = true; // Izinkan file yang dapat dieksekusi (tidak disarankan)
$allow_invalid_files = true; // Izinkan file tidak valid (tidak disarankan)
$allow_scripts = true; // Izinkan file skrip (tidak disarankan)
$allow_password_protected_files = true; // Izinkan file terenkripsi (tidak disarankan)
$allow_macros = true; // Izinkan file dengan makro (tidak disarankan)
$allow_xml_external_entities = true; // Izinkan Entitas Eksternal XML (tidak disarankan)
$allow_insecure_deserialization = true; // Izinkan Deserialisasi Tidak Aman (tidak disarankan)
$allow_html = true; // Izinkan file HTML (tidak disarankan)
$restrict_file_types = "restrict_file_types_example"; // Batasi jenis file yang diizinkan

try {
    $result = $apiInstance->scanFileAdvanced($input_file, $allow_executables, $allow_invalid_files, $allow_scripts, $allow_password_protected_files, $allow_macros, $allow_xml_external_entities, $allow_insecure_deserialization, $allow_html, $restrict_file_types);
    print_r($result);
} catch (Exception $e) {
    echo 'Exception saat pemindaian: ', $e->getMessage(), PHP_EOL;
}
?>

Kesimpulan

Dengan pemindaian ini, kita dapat memblokir file yang mencurigakan secara kategoris tanpa bergantung sepenuhnya pada antivirus. Namun perlu dicatat bahwa pengaturan tertentu (tidak disarankan) meningkatkan risiko keamanan.

Terbaru

  • API Keys vs. Service Accounts vs. OAuth: How do you pick the right credential on Google Cloud?
  • Why Your Private Subnet is Offline: The DevOps Interview Breakdown
  • The Laravel-ification of Everything: Why Go and Rust are Racing to Steal PHP’s Crown
  • Why Redis is actually fast
  • The Fake 2FA Scandals and Fake AI Apps on Microsoft Store
  • Stop Overengineering Your Infrastructure: Docker Compose vs Kubernetes Resources
  • Traefik 3.8 New Feature: Yaegi v2 and the Gateway API Finally Make Custom Plugins Worth the Effort
  • Raspberry Pi OS: Why the November Update is a Win for Minimalism
  • React Can useState Hook Explained in 60 Seconds
  • How Do You Build an MMO Solo?
  • NixOS 26.11 “Zokor” Might Be the Most Practical Release for Desktop Power Users Yet
  • Why Your AWS Bill Can Just Tripled Overnight?
  • Why Indonesia’s Battle with Google is a Dangerous Game of Chicken
  • SYS010 Malware Explained: How Malvertising on Meta Bypasses MFA and Hijacks Your Digital Identity
  • Linux Mint 27 Adrien: Why This Version Jump is Make Sense?
  • NFS2ROOT: A 12-Year Reminder That Your Linux Kernel Is Never Truly Safe
  • The Death of Browsing and the Rise of the “Answer Engine Economy”
  • What’s new in Proxmox VE 9.3?
  • Why Your Morning Routine Needs an API: The Art of iOS Automation
  • Proof of Work is the New Certification: 5 AWS Projects to Build Before 2027
  • Omarchy is Our first agentic operating system
  • The Death of Popper.js: Why CSS Anchor Positioning is the New Standard for Connected UI
  • Why Your 2027 Cloud Career Depends on Moving Beyond Basic AWS Services
  • Why Discord is Ditching Electron for Rust: Is GPUi Actually the Future?
  • The End of the KDE Era: Why KaOS 2026.11 Is a Bold, Dangerous Gamble
  • The $2 Billion Code: Why GTA 6 is a Technical Miracle and a Hardware Nightmare
  • LibreDB Studio Explained
  • PHP 8.6 Is Officially Out: What’s New, What Breaks, and How We’re Upgrading
  • Rewriting Legacy Apps: 4 Data Migration Strategies That Actually Work
  • How to Install Clean Windows 11 Without Any Bloatware (Step-by-Step Guide)
  • Canonical: Ubuntu coming soon to Snapdragon X2 Series platforms
  • Finally, wolfSSL adds post-quantum algorithms!
  • How to Run Gemma Embedding Models Using Docker
  • Deploy Nginx Rootful Container with Podman
  • How to Sandboxing Browser on Linux Desktop with Flatpak
  • The Qwen4-35B-A3B: Is This the “Impossible” Model for Local AI?
  • Why Running LLMs Locally in Python is No Longer Optional for Serious Developers
  • Digital Ghetto: People are hacking their own houses with Claude
  • How to Let ChatGPT Control Your Computer From Your Phone (Step-by-Step)
  • Ternary Bonsai 2.5 at 215 TPS! Splash + DFlash2 on Apple M5 Max

©2026 emka.web.id | Design: Newspaperly WordPress Theme