# easy-invoice/2.4.0/includes/Helpers/UploadGuard.php

Easy Invoice – Invoice Generator, PDF Quotes &amp; Payments, version 2.4.0. 42 lines.

- Page: https://pluginprobe.com/plugins/easy-invoice/2.4.0/code/includes/Helpers/UploadGuard.php
- Raw: https://pluginprobe.com/plugins/easy-invoice/2.4.0/raw/includes/Helpers/UploadGuard.php
- Modified: 2026-09-15T12:31:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/easy-invoice/2.4.0/code/includes/Helpers/UploadGuard.php#L10-L20`.

```php
<?php
/**
 * Keeps plugin upload folders from being listed.
 *
 * @package EasyInvoice
 */

namespace EasyInvoice\Helpers;

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

class UploadGuard {
    /**
     * Drop an index.php (and an .htaccess turning indexes off) into a folder
     * the plugin writes client files to, so a directory listing never shows
     * every payment proof or signature. Idempotent; silent on failure.
     *
     * @param string $dir Absolute path.
     */
    public static function protectDirectory( string $dir ): void {
        if ( '' === $dir ) {
            return;
        }
        if ( ! is_dir( $dir ) ) {
            wp_mkdir_p( $dir );
        }
        if ( ! is_dir( $dir ) || ! is_writable( $dir ) ) {
            return;
        }
        $index = trailingslashit( $dir ) . 'index.php';
        if ( ! file_exists( $index ) ) {
            @file_put_contents( $index, "<?php\n// Silence is golden.\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions,WordPress.PHP.NoSilencedErrors
        }
        $htaccess = trailingslashit( $dir ) . '.htaccess';
        if ( ! file_exists( $htaccess ) ) {
            @file_put_contents( $htaccess, "Options -Indexes\n" ); // phpcs:ignore WordPress.WP.AlternativeFunctions,WordPress.PHP.NoSilencedErrors
        }
    }
}

```
