Im working on project right now in webdevelopment. im trying to view a PDF file in a browser which is the filepath was stored in database and the actual file save was in folder inside my webfolder and could retrieve/view by its ID. here's some of my code



    $con = new PDO("mysql:host=localhost;dbname=qfms","root","");

    $fid = $_POST['id'];
    $stmt = $con->prepare("SELECT filename FROM rabbit_tbl WHERE id= '" .$fid. "'");


    while($row = $stmt->fetch()){
        header('Content-type: application/pdf');
        header("Content-Disposition: inline");
        echo "/pdffiles" .$row['id']. ".pdf");
        echo "Enter id";


My issue here, when i run/compile it, it says "Failed to load PDF document". what am i missing here? do you have any suggestions, tutorial link?

Thanks guys.

Member Avatar

Doesn.t make any sense. You.re pulling one record yet are running a while loop. Why? What.s readfiles supposed to be doing? Reading the directory?

You may read this thread. As @diafol said, your code doesn't make sense. You are expecting ONLY 1 record from your query, so using while loop is unnecessary (or does not make sense).