0

I try to display a pdf document with code like this:

<?php
    session_start();
    if (empty($_SESSION['nip']) AND empty($_SESSION['password'])) {
        ?>
        <script type='text/javascript'>
            alert('You must login');
            document.location='../../../login.php';
        </script>
        <?php
    }else{
        include_once '../../../config/core.php';
        include_once '../../../config/functioncollection.php';
        $kode_materi=antiInjections($_GET['id']);
        $querambildata=mysql_fetch_array(mysql_query("SELECT * FROM materi_tb WHERE kode_materi='$kode_materi'"));

        $file = "../../../filemateri/".$querambildata['url_materi'];
        $filename = $querambildata['url_materi'];
        header('Content-type: application/pdf');
        header('Content-Disposition: inline; filename="' . $filename . '"');
        header('Content-Transfer-Encoding: binary');
        header('Accept-Ranges: bytes');
        @readfile($file);
    }
?>

but when I opened, even download the file. how not to automatically download but just open the pdf file. thank you in advance

2
Contributors
1
Reply
10
Views
2 Years
Discussion Span
Last Post by pixelsoul
0

Your file name ends with '.pdf' correct? Everything looks okay to me after that. You might want to add this as well.

header('Content-Length: ' . filesize($file));

See if that makes any difference.

Make sure you're testing in more than one browser/machine, it might just be your machine that is doing it. Ultimately, the behavior is decided by the browser/software settings on the pc I believe.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.