0

Hi,
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

<?php 

    if(isset($_POST['search'])){

    $con = new PDO("mysql:host=localhost;dbname=qfms","root","");
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

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

    $stmt->execute();

    while($row = $stmt->fetch()){
        header('Content-type: application/pdf');
        header("Content-Disposition: inline");
        echo "/pdffiles" .$row['id']. ".pdf");
        readfile('pdffiles/');
    }
}else{
        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.

3
Contributors
3
Replies
21
Views
1 Year
Discussion Span
Last Post by OtepTheThird
1

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?

1

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).

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.