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 for diafol

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

Thanks @Taywin and @diafol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.