read pdf files with php directly in browser

-3

Colleagues. Is it possible to open a PDF file directly inside the browser? I tried the file_get_contents () and fopen (), but it opened from decoded. So I tried it that way, but it opened in the entire browser:

$arquivo='0eb178d150b82f5536588fbfea5fa7bd.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="0eb178d150b82f5536588fbfea5fa7bd.pdf"');
 @readfile($arquivo);
    
asked by anonymous 16.05.2016 / 21:01

1 answer

1
<?php
$file = './path/to/the.pdf';
$filename = 'Custom file name for the.pdf'; /* Note: Always use .pdf at the end. */

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $filename . '"');
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');

@readfile($file);
?>

Source: link

Code working link

    
16.05.2016 / 23:40