WordPress: Securing/Escaping Output of file content - reading via @fread() in PHP

Viewed 30

I am working on securing the content read from a file via the @fread() function.

private function readfile_chunked($file) {
    $chunksize = 1024 * 1024;

    // Open Resume
    $handle = @fopen($file, 'r');

    if (false === $handle) {
        return FALSE;
    }

    while (!@feof($handle)) {
        $content  = @fread($handle, $chunksize);
        echo wp_kses_post( $content);

        if (ob_get_length()) {
            ob_flush();
            flush();
        }
    }

    return @fclose($handle);
}

The aforementioned wp_kses_post($content) is suggested by the WP plugin review team to secure the file content but this solution is not working for me. It is downloading the file in a loop. Any help will be appreciated on "How we can escape output of @fread() in WordPress?". Or any alternative function so we can skip the "echo" function.

Thanks

0 Answers
Related