Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9096461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T23:51:31+00:00 2026-06-16T23:51:31+00:00

i got this code in attaching a pdf file to my site in order

  • 0

i got this code in attaching a pdf file to my site in order for the viewers to download such pdf file..

$fullPath = “../public/pdffiles/FolioPlusUserGuide(v3.0).pdf”;

    if ($fd = fopen ($fullPath, "r")) {

        $fsize = filesize($fullPath);
        $path_parts = pathinfo($fullPath);
        $ext = strtolower($path_parts["extension"]);

        header("Content-type: application/pdf");
        header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");            
        header("Content-length: $fsize");
        header("Cache-control: private");

        while(!feof($fd)) {
            $buffer = fread($fd, 2048);
            echo $buffer;
        }
    }

    fclose ($fd);
    exit;

html code:

baseUrl().’/DownloadPdf’?>”>DOWNLOAD BROCHURE

this code only accommodates 1 file path, I have more pdf files with different filename and different buttons for each to handle the download event. how can i achieve this?..thanks ahead!..=)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T23:51:32+00:00Added an answer on June 16, 2026 at 11:51 pm

    You can pass PDF file name via HTTP request, like this:

    DownloadPDF.php?filename=test1.pdf

    Then in your DownloadPDF file have something like this:

    $pdfdir = "/pdffiles/folder/location/here";
    $pdffilename = $_GET['filename'];
    $fullPath = $pdfdir.$pdffilename;
    
    if ($fd = fopen ($fullPath, "r")) {
    
            $fsize = filesize($fullPath);
            $path_parts = pathinfo($fullPath);
            $ext = strtolower($path_parts["extension"]);
    
            header("Content-type: application/pdf");
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\"");            
            header("Content-length: $fsize");
            header("Cache-control: private");
    
            while(!feof($fd)) {
                $buffer = fread($fd, 2048);
                echo $buffer;
            }
        }
    
        fclose ($fd);
        exit;
    

    Now your code is dynamic and you can download any PDF with links like this:

    <a href=downloadpdf.php?filename=something.pdf>Something</a>
    <a href=downloadpdf.php?filename=something2.pdf>Something2</a>
    

    etc.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Got this code for a viewscroller from the apple developers site. @synthesize scrollView1, scrollView2;
I got this code in order to build an url for the link using
I´ve got this code inside a php file. It should show and hide a
I got this code: public void make_square(View v) { TextView txt_wait = (TextView) findViewById(R.id.square_txt);
I got this code from this site: http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/using-php-to-backup-mysql-databases.aspx But I'm just a beginner so
I got this code inside a small program to read a file: #ifdef WIN32
Got this code in C#: using System; public class Listener{ public static void Main(){
I got this code: function datatable_display(json) { var order = desc; var len =
I got this code from our frontend guy for headings: <h2 class=headline><span>Foobar</span></h2> The span
I got this code from the wordpress <head profile=http://gmpg.org/xfn/11> What does this means? what

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.