PHP code example of arraypress / wp-file-utils

1. Go to this page and download the library: Download arraypress/wp-file-utils 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/ */

    

arraypress / wp-file-utils example snippets


use ArrayPress\FileUtils\MIME;
use ArrayPress\FileUtils\Path;

// The check that matters: is the requested file really inside our directory?
if ( ! Path::within( $requested, $downloads_dir ) ) {
    wp_die( 'Not found', 404 );
}

// Never render an untrusted upload inline.
if ( MIME::is_dangerous_inline( $file ) ) {
    header( 'Content-Disposition: attachment' );
}

header( 'Content-Type: ' . MIME::of( $file ) );